1

We have a system that displays the Dates based on the Locale chosen by the user. A customer is requesting to have the date format of a locale to be similar to the en_US format. The problem is that it is not possible to perform code changes.

Is there a way to change the date format for a Timezone on the JVM level? Maybe something similar to the IANA timzezone change TZUpdater?

Thank you.

Edit: This is not a duplicate and the links in the comments are not similar. I don't want to set the default Local, I want to map the Date Format for the New Zealand English dates to be similar to the Date Format for the Untied States English date Format.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
  • 1
    See these questions: [1](http://stackoverflow.com/questions/8809098/how-do-i-set-the-default-locale-for-my-jvm), [2](http://stackoverflow.com/questions/64038/setting-java-locale-settings) – apangin Feb 13 '17 at 11:55
  • Possible duplicate of [how do I set the default locale for my JVM?](http://stackoverflow.com/questions/8809098/how-do-i-set-the-default-locale-for-my-jvm) – Derlin Feb 13 '17 at 11:56
  • 2
    No, it is not duplicate and the links above are not similar. I don't want to set the default Local, I want to map the Date Format for the New Zealand English dates to be similar to the Date Format for the Untied States English date Format. – user7557454 Feb 13 '17 at 12:03
  • Could you please give an example? Date formats express "common" data (like timestamps) in a locale specific way. How do you "map" that?! – GhostCat Feb 13 '17 at 12:08
  • 1
    Sure, when you get the Date Format in the New Zealand English Locale, it will be displayed as 09/02/2017, in the United States English Format, it will be displayed as Feb 9, 2017. The customer wants the users who are using the New Zealand English Locale to have the dates displayed as Feb 9, 2017. The format is determined by the JVM based on the chosen Locale. Thank you. – user7557454 Feb 13 '17 at 12:22
  • I have the same issue. Customer wants medium format for German locale to by MMM dd, yyyy not dd.MM.yyyy. – yaroslav prokipchyn Jun 13 '17 at 12:29

1 Answers1

3

Date formats for a given locale are loaded from sun.text.resources.FormatData Resource Bundle. The resources for en_* locales are embedded in rt.jar, that is, exist in the bootstrap classpath.

To override resources for a given locale you have to replace the corresponding Resource Bundle somehow. There are several ways to do this, for example:

  1. Create an empty file sun/text/resources/en/FormatData_en_NZ.class, place it into a directory or into a JAR, which is prepended to bootstrap class path using -Xbootclasspath/p:<dir> JVM option.
  2. Create a Java Agent that registers a ClassFileTransformer to modify FormatData_en_NZ class data during class loading.
  3. Replace or remove sun/text/resources/en/FormatData_en_NZ.class file directly in rt.jar (not recommended).
apangin
  • 92,924
  • 10
  • 193
  • 247
  • Can you add some more details about the second approach? Firs and third approaches are not applicable because we have many app instances on production and we don't control deployment and maintenance of production. – yaroslav prokipchyn Jun 13 '17 at 12:32
  • @yaroslavprokipchyn What do you mean by *"don't control deployment and maintenance"*? Can you change JVM arguments used to launch the application? – apangin Jun 14 '17 at 16:38
  • Theoretically, I can request it. But a lot of admins DevOps and others will be very unhappy with adding new steps to release. Thanks for responding – yaroslav prokipchyn Jun 15 '17 at 08:55