Question

When my app loads, I get device's settings in order to display dates/times according to user's locale. As seen on the image below, the pattern is correct, but the am/pm marker is not translated to the corresponding language (in this case language is Greek, local is "el_GR"). Is there a way to fix that?

"am/pm" should be automatically translated to "πμ/μμ"


public static final DateFormat USER_DF_TIME = DateFormat.getDateTimeInstance(DateFormat.SHORT,
        DateFormat.SHORT, Locale.getDefault());

enter image description here

Était-ce utile?

La solution

After further investigation, I found a similar bug for Java 6, "Swedish localization has incorrect am/pm markers".The bug was reported back in 2007 and was finally resolved in 2011.

Also, according to the official Oracle page "The set of supported locales varies between different implementations of the Java Platform Standard Edition (Java SE)".

Testing my code on various devices I found out that it worked correctly on android 4.1.2 and 4.4, but the problem remains for my android 4.1.1 device. Given that old android's Java version is similar to Java 6 I infer that it's a Java language problem that is solved in newer versions.

Autres conseils

I don't see an problem with your code.

    private static final Locale GREEK_LOCALE = new Locale("el", "GR");
    public static final DateFormat USER_DF_TIME = DateFormat.getDateTimeInstance(DateFormat.SHORT,
            DateFormat.SHORT,GREEK_LOCALE );
    String dateString =USER_DF_TIME.format(new java.util.Date());
    System.out.println(dateString);

Returning 15/5/2014 2:11 μμ properly ( I am in EST now)

Seems you have issues with default locale. Follow https://stackoverflow.com/a/4212671/2182351 to get correct locale

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top