@Test
 public void testTimeEntityToStringReturnsFormattedGMTDateTime() throws Exception {
   Date then = new Date(123456789012L);
   TimeEntity aTime = new TimeEntity(then);
   aTime.setTz(TimeZone.getTimeZone("GMT"));
   DateFormatter formatter = new DateFormatter("MM/dd/yyyy hh:mm:ss");
   formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
   String expected = formatter.print(then, Locale.getDefault());
   assertEquals(expected, aTime.toString());
 }
示例#2
0
 @Bean
 public FormattingConversionService conversionService() {
   DefaultFormattingConversionService conversionService =
       new DefaultFormattingConversionService(false);
   conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());
   DateFormatterRegistrar registrar = new DateFormatterRegistrar();
   DateFormatter dateFormatter = new DateFormatter();
   dateFormatter.setIso(ISO.DATE);
   registrar.setFormatter(dateFormatter);
   registrar.registerFormatters(conversionService);
   return conversionService;
 }
 protected Formatter<Date> getFormatter(DateTimeFormat annotation, Class<?> fieldType) {
   DateFormatter formatter = new DateFormatter();
   formatter.setPattern(dateTimePattern);
   return formatter;
 }