0

Can anyone point out what seems to be the problem here?

try {
    Date date = new SimpleDateFormat("Mon, 02 Nov 2015 15:13:00 EET").parse("EEE, dd MMM yyyy hh:mm:ss z");
} catch (ParseException e) {
    e.printStackTrace();
}

and the stacktrace:

java.text.ParseException: Unparseable date: "Mon, 02 Nov 2015 15:13:00 EET" (at offset 26)

I'm suspecting something with the locale that I'm using but I can't be sure. Seems that "z" for timezone not working.

Edit: Sorry the exception was funny earlier, I changed it but forgot to update here.

try {
            Date date = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss z", Locale.US).parse("Mon, 02 Nov 2015 15:13:00 EET");
        } catch (ParseException e) {
            e.printStackTrace();
        }
6
  • 1
    You have the arguments backwards. pass the format string to SimpleDateFormat contructor and the actual date string to parse Commented Nov 20, 2015 at 17:39
  • Sorry about that, I forgot to update the code earlier, here's the real one with that exception. The old one was giving some kinda funny exception like "no pattern 'o' " or something Commented Nov 20, 2015 at 17:41
  • next guess would be that EET is not a recognized timezone Commented Nov 20, 2015 at 17:42
  • What I meant is that I get the unparseable date exception with the right order Commented Nov 20, 2015 at 17:42
  • Have you tried with Locale.ENGLISH ? what is the Locale in your system ? The string is parsed into a date just fine in my system Commented Nov 20, 2015 at 17:44

3 Answers 3

1

After looking at javadoc for SimpleDateFormat, you are using "hh" for hour, which is assumed to be a 12-hour time. Use HH for 24-hour time. Your example as 15 for the hour.

Sign up to request clarification or add additional context in comments.

3 Comments

Yea I changed that one, thank you for declaring but that's not the problem. I think when you use hh it mods your value since the problem is at offset 26, and it still is after i changed it to HH.
Then I'm back to the timezone EET not being recognized by Java, even if it's a valid timezone. Try replacing EET with EST.
Yea seems its working with EST. Too bad it's a feed and can't change it. Guess I'll split and hope that feed won't change. Thank you :)
0

I think you're missing 'z' here.

Try:

Date date = new SimpleDateFormat("Mon, 02 Nov 2015 15:13:00 EET").
        parse("EEE, dd MMM yyyy hh:mm:ss zzz")

Since your timezone is with three characters.

1 Comment

I don't think that's the case. In oracle documentation they gave this example "K:mm a, z" 0:08 PM, PDT. But not that it matters, I tried every combination from 1 to 4 z just to make sure earlier capital or lower :)
0

Such an exception can come from parsing a date with the wrong Locale. For example this date formatter :

SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss z", Locale.US);

will successfully parse the example date :

Date date = df.parse("Mon, 02 Nov 2015 15:13:00 EET");

But the following will give the exception you are getting

SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss z", Locale.FRENCH);

I would expect the Locale in Android to be chosen according to the language set by the user.

1 Comment

But I'm already creating the simpleDateFormatter instance with Locale.US, would it not be the case to use Locale.getDefault() to get the exception?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.