-1

I have this

java.text.ParseException: Unparseable date: "Thu, 21 Apr 2016 18:00:00 +0000" (at offset 26)

when using new SimpleDateFormat("E, dd MMMM yyyy hh:mm:ss a", Locale.ROOT);

Why is that can be?

EDIT:

This is correct answer due to parsing pattern.

SimpleDateFormat f = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ROOT);

And also Android somehow gives error when the Locale is ROOT and when it is ENGLISH everything works fine.

Kyryl Zotov
  • 1,788
  • 5
  • 24
  • 44

2 Answers2

3

You are using the wrong format. You should be using EEE, dd MMM yyyy HH:mm:ss Z instead of E, dd MMMM yyyy hh:mm:ss a.

Here is the code snippet:

public static void main (String[] args) throws Exception
{
    String foo = "Thu, 21 Apr 2016 18:00:00 +0000";
    SimpleDateFormat f = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ROOT);
    System.out.println(f.parse(foo));
}

Output:

Thu Apr 21 18:00:00 GMT 2016
user2004685
  • 9,548
  • 5
  • 37
  • 54
  • I don't understand why it happens but it works at emulator but fails at real devices - giving this error. It is in asynktask by the way – Kyryl Zotov Mar 11 '16 at 13:13
2

Use EEE, dd MMM yyyy HH:mm:ss Z

Febi M Felix
  • 2,799
  • 1
  • 10
  • 13
  • I don't understand why it happens but it works at emulator but fails at real devices - giving this error. It is in asynktask by the way – Kyryl Zotov Mar 11 '16 at 13:13