Search code examples
javasimpledateformatparseexception

java.text.ParseException: Unparseable date from ("d MMM yyyy kk:mm:ss zzz")


I get ParseException in second line of the folowing code:

SimpleDateFormat formatter = new SimpleDateFormat("d MMM yyyy kk:mm:ss zzz");
Date response = formatter.parse(dateStr);

Exception:

java.text.ParseException: Unparseable date: "1 Dec 2014 08:32:59 GMT" (at offset 2)

How to solve this?


Solution

  • You need to set the Locale.

    SimpleDateFormat formatter = new SimpleDateFormat("d MMM yyyy kk:mm:ss zzz",
                                                                          Locale.US);
    Date response = formatter.parse("1 Dec 2014 08:32:59 GMT");
    System.out.println(response);