@Formats.DateTime(pattern="dd/MM/yyyy")
@Temporal(TemporalType.TIMESTAMP)
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
@Target({FIELD}) @Retention(RUNTIME) @play.data.Form.Display(name="format.date", attributes={"key"}) public static @interface DateTimePattern { String key();
}
public static class AnnotationDateFormatter extends Formatters.AnnotationFormatter<DateTimePattern,Date> {
public Date parse(DateTimePattern annotation, String text, Locale locale) throws java.text.ParseException {
if(text == null || text.trim().isEmpty()) { return null; } SimpleDateFormat sdf = new SimpleDateFormat(Messages.get(new Lang(locale.getLanguage(), locale.getCountry()), annotation.key()), locale); sdf.setLenient(false); return sdf.parse(text); }
public String print(DateTimePattern annotation, Date value, Locale locale) {
if(value == null) { return ""; } return new SimpleDateFormat(Messages.get(new Lang(locale.getLanguage(), locale.getCountry()), annotation.key()), locale).format(value); }
}
@Override public void onStart(Application application) { super.onStart(application);
Formatters.register(Date.class, new AnnotationDateFormatter());
}
But do you apply the @DateTimePattern annotation on your field?
@Formats.DateTimePattern(key="date.format") @Temporal(TemporalType.TIMESTAMP) public Date periodEnd;