Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the time zone from a datetime string

How can I get the time zone from a datetime string with this format 2013-08-15T13:00:00-07:00?

like image 414
Fei Qu Avatar asked Nov 27 '25 04:11

Fei Qu


2 Answers

You could take the time offset from Andreas answer and use below sinppet to get TimeZone object.

TimeZone tmzo = TimeZone.getTimeZone("GMT"+offset);
System.out.println(tmzo.getID());
like image 64
Vasco Avatar answered Nov 28 '25 16:11

Vasco


if Java 8, you can parse directly with ISO_ZONED_DATE_TIME format

String input = "2013-08-15T13:00:00-07:00";                             
ZonedDateTime zDateTime = ZonedDateTime.parse(input, DateTimeFormatter.ISO_ZONED_DATE_TIME);            
ZoneId zone = zDateTime.getZone();  
like image 45
Viet Avatar answered Nov 28 '25 18:11

Viet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!