@Test public void testDateDefaults() { assertEquals(FastDateFormat.getDateInstance(FastDateFormat.LONG, Locale.CANADA), FastDateFormat.getDateInstance(FastDateFormat.LONG, TimeZone.getDefault(), Locale.CANADA)); assertEquals(FastDateFormat.getDateInstance(FastDateFormat.LONG, TimeZone.getTimeZone("America/New_York")), FastDateFormat.getDateInstance(FastDateFormat.LONG, TimeZone.getTimeZone("America/New_York"), Locale.getDefault())); assertEquals(FastDateFormat.getDateInstance(FastDateFormat.LONG), FastDateFormat.getDateInstance(FastDateFormat.LONG, TimeZone.getDefault(), Locale.getDefault())); }
@SystemDefaults(locale="en_US") @Test public void test_changeDefault_Locale_DateInstance() { final FastDateFormat format1 = FastDateFormat.getDateInstance(FastDateFormat.FULL, Locale.GERMANY); final FastDateFormat format2 = FastDateFormat.getDateInstance(FastDateFormat.FULL); Locale.setDefault(Locale.GERMANY); final FastDateFormat format3 = FastDateFormat.getDateInstance(FastDateFormat.FULL); assertSame(Locale.GERMANY, format1.getLocale()); assertEquals(Locale.US, format2.getLocale()); assertSame(Locale.GERMANY, format3.getLocale()); assertNotSame(format1, format2); assertNotSame(format2, format3); }
public static String getDateFormat() { try { return FastDateFormat.getDateInstance( FastDateFormat.SHORT, MgnlContext.getLocale()).getPattern(); } catch (IllegalStateException e) { // this happens if the context is not (yet) set return DateUtil.YYYY_MM_DD; } }
/** * Uses the current locale (user) to format the date. * * @param val Date or Calendar * @return the String */ public static String formatDate(Object val) { if (val == null) { return StringUtils.EMPTY; } FastDateFormat format = FastDateFormat.getDateInstance( FastDateFormat.SHORT, MgnlContext.getLocale()); return format.format(val); }