3

I am trying to use java.time.format.DateTimeFormatter to parse dates like "2017-04-03 19:16:19 Etc/GMT" and getting java.time.format.DateTimeParseException: Text '2017-04-03 19:16:19 Etc/GMT' could not be parsed at index 20

Here is how my formatter is being initialized:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss zzz");

At the same time, if date is as follows: "2017-04-03 19:16:19 Etc/UTC", everything works great.

I checked java.time.ZoneId.getAvailableZoneIds() - String "Etc/GMT" is in the list (technically, in the Set).

Any ideas?

5
  • 1
    Use "yyyy-MM-dd HH:mm:ss VV" Commented Apr 5, 2017 at 22:44
  • That was quick! Thank you! Can you post it as an answer? Commented Apr 5, 2017 at 22:54
  • 1
    Question is not useful for others. Javadoc of DateTimeFormatter already shows that V is the format letter for matching named time zones, not z. Just delete the question. Commented Apr 5, 2017 at 22:56
  • Well, I guess I'm the only one out there who can waste a couple of hours on stuff like that... Commented Apr 5, 2017 at 22:59
  • 1
    @Andreas - That's worth putting in an answer, IMHO. Commented Apr 7, 2017 at 0:04

1 Answer 1

5

Use DateTimeFormatter pattern "yyyy-MM-dd HH:mm:ss VV":

V       time-zone ID                zone-id           America/Los_Angeles; Z; -08:30
z       time-zone name              zone-name         Pacific Standard Time; PST

As you can see, the V pattern will format/parse a Zone Id, like America/Los_Angeles and Etc/GMT, while the z pattern only formats/parses the Zone Name.

The V pattern must be at least 2 long, i.e. VV.

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

Comments

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.