cancel
Showing results for 
Search instead for 
Did you mean: 

Map Locale to DateFormat

Former Member
0 Kudos

Hi,

What is the right way to map a Locale to a DateFormat object so that the mapping applies for all applications running on the j2ee engine?

Using DateFormat.getDateInstance(int style, Locale aLocale) one can get a DateFormat object for a certain Locale, but I didn't found any info on how to edit the mapping.

Thanks,

Jeroen

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

maybe

Locale.setDefault(Locale new) will work for you

see

<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Locale.html#setDefault(java.util.Locale)">Java Docs</a>

Franz

reward points if useful

Answers (1)

Answers (1)

former_member185029
Active Contributor
0 Kudos

Hi,

Check following code.


Locale locale= new Locale("en");
DateFormat df= DateFormat.getDateInstance();
 df.setNumberFormat(NumberFormat.getInstance(locale));

Ashu

Former Member
0 Kudos

Hi,

I don't see how your code is registering a DateFormat for a given locale for all portal applications.

In other words: if i want all portal applications to use a different DateFormat for the en/UK Locale then the one provided by Sun/IBM, how can I achieve that?

Jeroen

former_member185029
Active Contributor
0 Kudos

Hi,

Do you want to enforce default Locale for different portals?


Locale locale = Locale.getDefault();

Ashu

Former Member
0 Kudos

Hi Jeroen,

I guess the quickest way would be to decompile the sun.text.resources.LocaleElements_en_GB class which is part of the rt.jar (at least for the SUN VM; the mechanism might be different for other VMs), patch its getContents() method, compile your class and either patch the rt.jar file or prepend the bootclasspath with the path to where your modified class is compiled. You can use the -Xbootclasspath/p:<targetPath> option for that, but note that according to the Java 1.5 documentation that I have on my machine, SUN considers this against the Java binary code license (things might be different now with Java being Open Source, but IANAL).

Hope that helps you.

Best Regards,

Jens

Former Member
0 Kudos

Hi,

Ok so probably it's not supported by Sun. I'm not gonna decompile etc because that's overkill for my problem and any upgrade of JVM would undo that..

Thanks for your reply.