balu balu - 1 year ago 66
Java Question

Convert Japan's date format (2013年11月24日) to normal date format (2013-11-24)

I have a date picker field on my JSP page. While selecting that field, the date is displayed in Japanese format (

) in my text field. Now, while reading that date field in my controller, I am getting this value

How can I convert this date format into normal date format?

Answer Source

It seems the format you've given is the default date format of the Japanese locale, so you can use the build in facility:

    DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, new Locale("ja"));


IDEONE example:

DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, new Locale("ja"));
System.out.println(df.format(new Date()));



Sun Nov 24 00:00:00 GMT 2013


Please note that this DateFormat class is not thread-safe, so you cannot make the instant static. If you do not want to create the instance again and again like above, you may want to look into the thread-safe variant in Joda time: DateTimeFormat.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download