3

The SimpleDateFormat below parses all the other TimeZone's I tried but doesn't seem to recognise EDT?

private static final SimpleDateFormat currentDateFormat = 
    new SimpleDateFormat("EEE, d MMM yyy h:mm a z");

ParseException: Unparseable date: "Sun, 15 Mar 2015 12:50 pm EDT" (at offset 26)

I've temporarily cut off the timezone from the date string so that it parses correctly.

Ozzy
  • 8,244
  • 7
  • 55
  • 95
  • What does `TimeZone.getTimeZone("America/New_York").getDisplayName(true, TimeZone.SHORT)` yield? Is it "EDT" or something else? Make also sure that you use English as your default locale. If the test result is not "EDT" then the cause of your problem is probably that your Android-version manages a different set of timezone names and abbreviations. – Meno Hochschild Mar 16 '15 at 11:44
  • @Ozzy Did you resolve this? – Jared Burrows Apr 04 '15 at 14:24
  • @JaredBurrows Yes, with a work-around. Took off the " z" from the format and used a function to calculate time-zone differences for 3-letter timezones. Will post the answer later when I'm not too busy. – Ozzy May 18 '15 at 21:41

1 Answers1

0

Based on this answer: https://stackoverflow.com/a/999191/950427 and reading the SimpleDateFormat docs here:http://developer.android.com/reference/java/text/SimpleDateFormat.html.

The seemed to use 3 "z"s for the time format:

Format:

Thu Jun 18 20:56:02 EDT 2009"

Their Answer:

new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");

You need to change:

new SimpleDateFormat("EEE, d MMM yyy h:mm a z");

To:

new SimpleDateFormat("EEE, d MMM yyy h:mm a zzz");
Community
  • 1
  • 1
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185