0

I already know how to find the "short" date-format pattern Java is using for a particular locale. However, in C# I can go further than this; I can find all customary "short" date format patterns for a particular locale.

Java, Pre SE 8

  • Is it possible to do the same thing in Java?
  • If yes, are the values returned standard to the Java platform, or are they OS specific? In other words, could the results I receive vary based on my installation or environment? Java Localized Date Formats

Based on this SO answer, I suspect the date formats (Pre SE 8) are not dependent on the OS.

Java, Post SE 8

  • Is it possible to do the same thing in Java?
  • If yes, are the values returned standard to the Java platform, or are they OS specific? In other words, could the results I receive vary based on my installation or environment?
Community
  • 1
  • 1
Brent Arias
  • 29,277
  • 40
  • 133
  • 234
  • Is there any formal definition of "all short date formats" for any locale, even the US English locale? I mean, yes, we can think of several, but there are probably very few which are recommended by publishing style guides. As @PawełDyda points out, the Unicode CLDR is probably the only official source. – VGR Nov 06 '14 at 18:32

1 Answers1

0

As they say, anything is possible for those who try. If you know how to get pattern for a single Locale, you can easily get pattern for all supported Locales. Here is how:

Locale[] locales = DateFormat.getAvailableLocales();
for (Locale locale : locales) {
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    if (df instanceof SimpleDateFormat) { // For the time being it will always be...
        SimpleDateFormat sdf = (SimpleDateFormat) df;
        System.out.println(sdf.toPattern());
    }
}

It is and probably always remain OS-independent. In Java 8 there are also other formats available, basically the ones from CLDR - Unicode Common Locale Data Repository but it requires quite an effort to put ones hand on them.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Paweł Dyda
  • 18,366
  • 7
  • 57
  • 79