• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to geneate similar date formats for different locales?  RSS feed

 
david zhang
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 56587
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 56587
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome

. . . but other people might have useful ideas.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!