| Author |
How to geneate similar date formats for different locales?
|
david zhang
Greenhorn
Joined: Oct 12, 2003
Posts: 27
|
|
I am hoping to generate dates with the following formats:
1. mm/dd/yyyy for US English
2. yyyy-mm-dd for Chinese
I am using DateFormat.getDateInstance(DateFormat.MEDIUM, locale) to produce output. I got the correct result for Chinese. For English, I got something like "May 30, 2010", but I hope to have 5/30/2010. How can I do this without adding if-statements? Adding if-statements would lead to difficulty in maintaining if I have to add more locales.
I think there must be some configuration or elegant way somewhere.
Thanks for help!
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
Too difficult for "beginning Java", so I shall move this thread.
Start with the internationalization pages in the Java™ Tutorials. Consider configuration files for different Locales. Consider loading Locale and DateFormat objects into a Map.
|
 |
david zhang
Greenhorn
Joined: Oct 12, 2003
Posts: 27
|
|
Campbell,
I understand your suggested approach. It should work, but I feel confiugration file/Map might be an overkill. I was hoping to be able to configure Java itself so that DateFormat.MEDIUM would produce right results for English. This may not be doable.
Thanks so much for chiming in!
Cheers.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
You're welcome
. . . but other people might have useful ideas.
|
 |
 |
|
|
subject: How to geneate similar date formats for different locales?
|
|
|