-5

I have the error in this line:

String mDate = new SimpleDateFormat("dd MM yyyy").format(new SimpleDateFormat("EEE MMM dd kk:mm:ss zZZZ yyyy").parse(myDate.toString()));

Error:

java.text.ParseException: Unparseable date: "Thu Dec 14 00:00:00 GMT+02:00 2017" (at offset 0)

If the error happens due incorrectly pattern then what pattern will be proper for this format of date?

I know that many topics exist with similar problems. But the key to my questions is proper date format for my date.

ddarellis
  • 3,912
  • 3
  • 25
  • 53
Yevgen
  • 93
  • 1
  • 1
  • 8
  • 1
    Possible duplicate of https://stackoverflow.com/questions/19873864/android-parsing-string-to-date-time-with-simpledateformat – Ramesh sambu Dec 13 '17 at 10:54
  • 6
    Possible duplicate of [Android parsing String to Date time with SimpleDateFormat](https://stackoverflow.com/questions/19873864/android-parsing-string-to-date-time-with-simpledateformat) – IntelliJ Amiya Dec 13 '17 at 10:55
  • My subject isn't duplicate. There is another date format. – Yevgen Dec 13 '17 at 11:01
  • See [SimpleDateFormat](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html), you should only have `EEE MMM dd kk:mm:ss z yyyy` iso `EEE MMM dd kk:mm:ss zZZZ yyyy`. So removing `ZZZ` – Pieter Dec 13 '17 at 11:19

1 Answers1

2

What is your default locale?

If you run this:

System.out.println(new SimpleDateFormat("EEE MMM dd kk:mm:ss zzzz yyyy", Locale.US)
            .parse("Thu Dec 14 00:00:00 GMT+02:00 2017"));

It will parse the date but if you run this:

System.out.println(new SimpleDateFormat("EEE MMM dd kk:mm:ss zzzz yyyy", Locale.GERMAN)
            .parse("Thu Dec 14 00:00:00 GMT+02:00 2017"));

Because Thu and Dec are English words. So check your default locale because if you don't pass a local to SimpleDateFormat it will take the default(if you dig around ) as shown here inside SimpleDateFormat class.

 Locale.getDefault(Locale.Category.FORMAT));
ddarellis
  • 3,912
  • 3
  • 25
  • 53