juretta.com

Java SimpleDateFormat: Don't forget to specify the locale

March 07, 2006
Tags: Dropbox Java

Assuming your current locale is non US the following piece of code will throw a ParseException: Unparseable date: "06-Mar-2006 12:35"

SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
date = format.parse("06-Mar-2006 12:35");

Note to myself: It's important to specify the correct Locale when parsing dates.

SimpleDateFormat format = 
    new SimpleDateFormat("dd-MMM-yyyy HH:mm", Locale.US);
date = format.parse("06-Mar-2006 12:35");

[1]: http://java.sun.com/.../Locale.html


blog comments powered by Disqus

About

juretta.com is the personal workspace of Stefan Saasen. More about this site can be found in the „About“ section.

Share!

Latest links  RSS  

More...