byteC0de
byteC0de

Reputation: 5273

How do I get the time zone id from a time zone

I want the country name(time zone id) based on time zone like

america/new_york

My current code is

String time_zone = TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT);

This returns GMT-05:00

Upvotes: 0

Views: 1100

Answers (2)

Andy Turner
Andy Turner

Reputation: 140318

The country is not part of the time zone data.

For instance, it's not reliably encoded in the ID, as in Africa/Abidjan or America/Cancun.

The only way you can do this is with an explicit lookup table mapping time zone id to country.

Upvotes: 3

Nilam Vaddoriya
Nilam Vaddoriya

Reputation: 443

you can get country name using this

TimeZone.getDefault().getID()

Upvotes: 3

Related Questions