0

I'm stuck parsing this String into a date.

"Thu Jun 09 2016 00:00:00 GMT+0200 (CEST)"

I made it that far: I can parse this string: "Thu Jun 09 2016 00:00:00 (CEST)" by using this formatter:

DateFormat formatter2 = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss (z)"

But I'm stuck with parsing the entire above String. Can anyone help?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
noneconnex
  • 29
  • 6
  • @Tunaki I don't think it's a duplicate: the input doesn't look like it can be (easily) parsed with a DateFormat. – assylias Jun 09 '16 at 08:42
  • assuming your input always contains the `GMT+xxxx` bit, you can probably make it work with `EEE MMM dd yyyy HH:mm:ss 'GMT'Z (z)` – assylias Jun 09 '16 at 08:44
  • Wow thanks assylias. And @Tunaki: please dont rate question as duplicate so easily. It causes a lot of bad vibes and lots of unnecessary frustration. Thank you. – noneconnex Jun 09 '16 at 08:46
  • @assylias Ha, `z` handles `GMT+02:00` (along with `CEST`) but not `GMT+0200` (without colon). This complicates matters indeed. Didn't know that... – Tunaki Jun 09 '16 at 08:59

1 Answers1

1

So thanks to assylias I made it. The correct formatter is:

DateFormat formatter = new SimpleDateFormat(
        "EEE MMM dd yyyy HH:mm:ss 'GMT'Z (z)", Locale.US);
Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
noneconnex
  • 29
  • 6
  • For the record, it's generally encouraged to ask people who answered in the comments to post their own answer. If they decline, or don't respond, you're free to post one just describing what worked, but it's a little more polite to give them a chance to get credit for what they did. – Nic Jun 15 '16 at 22:10