Search code examples
javadate

java how to parse date format?


In java, how to write this date format?

Dec 17 2011 07:37:55:000PM
SimpleDateFormat sdf = new SimpleDateFormat("M W yyyy hh:mm:ss:SSSa"); // failed

I tried this format, it doesn't work.

Please help, thanks.


Solution

  • I think you just need to expand your Month format to 3 M's and the days char is d not W.

    new SimpleDateFormat("MMM dd yyyy hh:mm:ss:SSSa");
                          ^^^ ^^
    

    Check here for more information on date formats http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html