2

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

kouretinho
  • 2,190
  • 1
  • 23
  • 37

2 Answers2

2

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.

Community
  • 1
  • 1
kouretinho
  • 2,190
  • 1
  • 23
  • 37
1

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

Community
  • 1
  • 1
Mani
  • 3,274
  • 2
  • 17
  • 27
  • thanks a lot for your input @Mani. It helped me look at the correct direction in order to find the problem (see below my detailed). May I ask which android version you tested the code on? – kouretinho May 16 '14 at 17:41
  • Hope the code does not required/use any Android SDK , So does it matter in Android ? (Note** i am not Android programmer) – Mani May 16 '14 at 17:46
  • So while you debug your code , you can see the actual value but while painting in Android panel are you facing this issue ? – Mani May 16 '14 at 17:47
  • When I ran your code in Eclipse, but outside of Android, I did new Locale("el", "GR"); and the output was correct. But when I did Locale.getDefault() on the physical device, the debugger showed me the image that I posted above. – kouretinho May 16 '14 at 17:48
  • There are some recommendation to take Default Locale value from Android. getResources().getConfiguration().locale http://stackoverflow.com/a/8747730/2182351 . I am not Android Expert to comment. So check it out. Seems the issue is not with the way you are formatting it is because of the Locale.getDefault. try to print hte Locale.getDefault value and post – Mani May 16 '14 at 17:55