aspose file tools
The moose likes Java in General and the fly likes How to geneate similar date formats for different locales? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to geneate similar date formats for different locales?" Watch "How to geneate similar date formats for different locales?" New topic
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
    
    4
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
    
    4
You're welcome

. . . but other people might have useful ideas.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to geneate similar date formats for different locales?
 
Similar Threads
Code review required for converting dateformat
Handling Multiple Date Formats Elegantly
Having trouble with Date Format in HSQLDB.
xsd datetime format
Locale and dates question