Reputation:
In java how do I display dates in different locales (for e.g. Russian).
Upvotes: 7
Views: 7895
Reputation: 1323183
Something like:
Locale locale = new Locale("ru","RU");
DateFormat full = DateFormat.getDateInstance(DateFormat.LONG, locale);
out.println(full.format(new Date()));
Should do the trick. However, there was a problem of Russian Date formatting in jdk1.5
The deal with Russian language is that month names have different suffix when they are presented stand-alone (i.e. in a list or something) and yet another one when they are part of a formatted date. So, even though March is "Март" in Russian, correctly formatted today's date would be: "7 Марта 2007 г."
Let's see how JDK formats today's date: 7 Март 2007 г. Clearly wrong.
Upvotes: 14
Reputation: 10987
Use SimpleDateFormat constructor which takes locale. You need to first check if JDK supports the locale you are looking for, if not then you need to implement that.
Upvotes: 5
Reputation: 81577
The DateFormat class can help you. As explained in the Javadoc:
To format a date for a different Locale, specify it in the call to getDateInstance().
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
So you just need to adapt this code by using the adequate Locale.
Upvotes: 3
Reputation: 44821
Use the java.text.DateFormat class, you can construct that's configured to a specific Locale.
DateFormat format = DateFormat.getDateInstance(DateFormat.MEDIUM, theLocaleYouWant);
String text = format.format(new Date());
System.out.println(text);
Upvotes: 4
Reputation: 64026
Use a java.util.Calendar with an appropriate time zone and locale.
Upvotes: 0