In java how do I display dates in different locales (for e.g. Russian).
Use a java.util.Calendar with an appropriate time zone and locale.
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);
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.
what about unicode characters, I want the date to be Mon, 8 December all in russian
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.
Locale.RUSSIAN does not appear in my IDE.Is this a problem with jdk or is there any thing else I need to use? I used a for loop and looped through Locale.getAvailableLocales() and I print out all characters for the date and for Russian I see ????. how can I display russian characters?
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.