This question already has an answer here:
I need to format date to app that has many languages, what is best way to format date, because every country has different kind of date formatting, so is it possible to format date by locale?
This question already has an answer here:
I need to format date to app that has many languages, what is best way to format date, because every country has different kind of date formatting, so is it possible to format date by locale?
SimpleDateFormat has a constructor which takes the locale, have you tried that?
http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html
Something like
new SimpleDateFormat("your-pattern-here", Locale.getDefault());
Yes, using DateFormat.getDateInstance(int style, Locale aLocale) This displays the current date in a locale-specific way.
So, for example:
See the docs for the exact meaning of the style parameter (
SHORT
,MEDIUM
, etc)Take a look at java.text.DateFormat. Easier to use (with a bit less power) is the derived class, java.text.SimpleDateFormat
And here is a good intro to Java internationalization: http://java.sun.com/docs/books/tutorial/i18n/index.html (the "Formatting" section addressing your problem, and more).
Joda-Time
Using the Joda-Time 2.4 library. The
DateTimeFormat
class is a factory ofDateTimeFormatter
formatters. That class offers aforStyle
method to access formatters appropriate to aLocale
.The argument with two letters specifies a format for the date portion and the time portion. Specify a character of 'S' for short style, 'M' for medium, 'L' for long, and 'F' for full. A date or time may be ommitted by specifying a style character '-' HYPHEN.
Note that we specified both a Locale and a time zone. Some people confuse the two.
We need all those pieces to properly generate a string representation of a date-time value.
I agree with Laura and the SimpleDateFormat which is the best way to manage Dates in java. You can set the pattern and the locale. Plus you can have a look at this wikipedia article about Date in the world -there are not so many different ways to use it; typically USA / China / rest of the world -