4

I have this string

Wed, 08 Jan 2014 9:30 am WET

and needed to be parsed to a Date object, I tried lot of masks but didn't work, here is the last thing I tried that I thought it would work with but didn't

SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm aaa z", Locale.ENGLISH);

thanks

stack trace

01-08 14:25:25.906: W/System.err(13288): java.text.ParseException: Unparseable date: "Wed, 08 Jan 2014 11:59 am WET"
01-08 14:25:25.914: W/System.err(13288):    at java.text.DateFormat.parse(DateFormat.java:626)

I ended up using this instead

SimpleDateFormat dateFormat     = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm aaa", Locale.ENGLISH);
Date date = dateFormat.parse(dateString.substring(0, dateString.length() - 4));

that WET part was the cause so I removed it, it wouldn't give the exact time but I only need the day and month,

3
  • that's what I found at Oracle web site Commented Jan 8, 2014 at 14:18
  • What is the WET at the end? Commented Jan 8, 2014 at 14:27
  • no idea, I think it's the zone, I got this from yahoo's website Commented Jan 8, 2014 at 14:28

1 Answer 1

5

Give a Locale to your Formatter where days and months are in English, otherwise it will use your default locale (that I presume is not English) and hence can't parse your String.

SimpleDateFormat dateFormat =
      new SimpleDateFormat("EEE, dd MMM yyyy hh:mm aaa z", Locale.ENGLISH);
Sign up to request clarification or add additional context in comments.

4 Comments

Post the stacktrace please, because it's working for me.
should that be hh:mm?
@turbo Yes I failed when I wrote it, sorry.
@user2427819 Check this thread : stackoverflow.com/questions/6299837/…

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.