Search code examples
javadate-formatsimpledateformat

What is the Date Format for "Fri Jun 05 00:00:00 PDT 2015"


I am trying to determine what java date format string to use for

"Fri Jun 05 00:00:00 PDT 2015"

Right now I am using

SimpleDateFormat format = new SimpleDateFormat("EEE MM dd HH:mm:ss zzzz yyyy");

But this yields

  com.fasterxml.jackson.databind.JsonMappingException: 
  java.text.ParseException: Unparseable date: "Fri Jun 05 00:00:00 PDT 2015" 
  (through reference chain:....

Solution

  • You need one additional M for the month:

    EEE MMM dd HH:mm:ss zzzz yyyy
    

    This is mentioned in the Javadocs of SimpleDateFormat:

    Month: If the number of pattern letters is 3 or more, the month is interpreted as text; otherwise, it is interpreted as a number.