7

Running:

Locale locale = Locale.US;
String pattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern(
        FormatStyle.LONG, 
        FormatStyle.LONG,
        Chronology.ofLocale(locale), 
        locale);
System.out.println("pattern: " + pattern);

Outputs:

pattern: MMMM d, yyyy h:mm:ss a z   // Java  8.0.171-oracle
pattern: MMMM d, y 'at' h:mm:ss a z // Java 11.0.0-open

I found that Oracle uses the iana-tz database (https://data.iana.org/time-zones/tz-link.html) for managing timezone data (see https://www.oracle.com/technetwork/java/javase/tzdata-versions-138805.html).

However, I did not find anything about such a change of the standard date formatting. Investigating the source code, it seems that in Java 8, the function LocaleResources.getJavaTimeFormatData() loads the sun.text.resources bundle, while in Java 11, it loads the sun.text.resources.cdlr bundle.

My question is: Is such a change documented somewhere, possibly with a reason for it?

Also, what is the best way to ensure compatibility with existing databases? For now, we have a list of recognized patterns, so I am thinking about adding the old patterns to my list of recognizable patterns by parsing the new patterns.

Another notable change is:

Locale locale = Locale.US;
String pattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern(
        FormatStyle.SHORT, FormatStyle.MEDIUM, Chronology.ofLocale(locale), locale);
System.out.println("pattern: " + pattern);

Outputs:

pattern: M/d/yy h:mm:ss a  // Java  8.0.171-oracle
pattern: M/d/yy, h:mm:ss a // Java 11.0.0-open
Michael
  • 41,989
  • 11
  • 82
  • 128
Rémi.B
  • 183
  • 10
  • My `Locale.getDefault()` is en_US. – Rémi.B Nov 15 '18 at 10:47
  • 1
    I've tested, and it's a change between 8 and 9. – Michael Nov 15 '18 at 10:51
  • 2
    Documentation: [Removed or changed APIs](https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-F7696E02-A1FB-4D5A-B1F2-89E7007D4096), scroll down to *Use CLDR Locale Data by Default*. – Ole V.V. Nov 15 '18 at 10:54
  • 1
    Also tested running with `-Djava.locale.providers=COMPAT` on Java 9 (as per first dupe) and that keeps the behaviour of Java 8. – Michael Nov 15 '18 at 10:55
  • 1
    Best way to ensure compatibility of database across Java versions: (1) Store datetimes using the DBMS’ native date and time types, not as strings. (2) If you need to store strings, store [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format. – Ole V.V. Nov 15 '18 at 11:13

0 Answers0