I have a LocalDate, and I would like to print the date with day and month as 2 digits, and the year 4 digits, based on the Locale format template. Actually, I can use DateTimeFormatter to set a short date, but unfortunately, “I cannot” change the default template ... Is there a way to do this?
Below I explain this with an example:
Locale l = Locale.ITALIAN;
LocalDate localDate = new LocalDate( 2014, 8, 28);
DateTimeFormatter formatterOutput1 = DateTimeFormat.shortDate().withLocale(l);
System.out.println( "Output1: " + formatterOutput1.print(localDate));
l = Locale.ENGLISH;
DateTimeFormatter formatterOutput2 = DateTimeFormat.shortDate().withLocale(l);
System.out.println( "Output2: " + formatterOutput2.print(localDate));
This is the result:
Output1: 28/08/14
Output2: 8/28/14
So, the conclusion is correct, but I expect this:
Output1: 28/08/2014
Output2: 08/28/2014
How to change the default template?
Thank!
source
share