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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With