SimpleDateFormat toPattern behaves differently in java 9

DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, new Locale("SV", "SE"));
((SimpleDateFormat) dateFormat).toPattern();

In Java 8, this line produces "yyyy-MM-dd", and in Java 9 - "y-MM-dd".

This has some serious issues for our legacy code, is there any way to return the behavior?

+4
source share
1 answer
    System.setProperty("java.locale.providers", "COMPAT,CLDR");
    DateFormat dateFormat
            = DateFormat.getDateInstance(DateFormat.SHORT, new Locale("sv", "SE"));
    System.out.println(((SimpleDateFormat) dateFormat).toPattern());

Running on my jdk-9.0.4, this prints

yyyy-mm-dd

You might want to set the property using -Dthe command line, it should not have any meaning.

Java 9 Common Locale Data Repository (CLDR) Unicode , Java. , , Java 8. nullpointer, : CLDR .

Basil Bourque , , , , sv, , .

, , y . , SimpleDateFormat, y 80-20: 80 20. yyyy . , 4- ( 1000 9999), , .

, :

DateTimeFormatterBuilder.getLocalizedDateTimePattern(
        FormatStyle.SHORT, null, IsoChronology.INSTANCE, new Locale("SV", "SE")));

(en-CY, , ) DateFormat DateTimeFormatter, , , DateFormat.

+4

Source: https://habr.com/ru/post/1693741/


All Articles