musicsquad musicsquad - 3 years ago 204
Java Question

Timezone format, how to know the timezone

I got a timestamp in the following format:

2017-09-27T16:19:24+0000


How do I know which timezone that is? What's the
DateTimeFormatter
if I'm using Java 8?

Al1 Al1
Answer Source

ZonedDateTime

As you stated using Java 8, you can leverage ZonedDateTime by using

ZonedDateTime zdt = ZonedDateTime.parse("2017-09-27T16:19:24+0000", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ")

Parsing rules are explained in DateTimeFormatter documentation. It is not exactly the ISO 8601 ISO_OFFSET_DATE_TIME as the offset should have been written +00:00 instead of +0000

Time zone vs time offset

Then, you can get the offset information with zdt.getZone(). However, you'll only get the Offset ID:

  • Z - for UTC (ISO-8601)
  • +hh:mm or -hh:mm - if the seconds are zero (ISO-8601)
  • +hh:mm:ss or -hh:mm:ss - if the seconds are non-zero (not ISO-8601)

As one comment said, be careful that time offset is not time zone: A given time zone (e.g. time in France) does not have the same offset the whole year (summer time vs winter time).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download