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.
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.
Joined: Oct 12, 2003
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.