Is there any country related info e.g. country code in the java.time
methods e.g. java.time.ZoneId
? I have a zone list retrieved via ZoneId.getAvailableZoneIds()
and I am wondering if there is a possibility to get any country data e.g. country code from it?
Asked
Active
Viewed 267 times
1

Jack
- 1
- 21
- 118
- 236
-
what exactly do you mean with country code? The Locale? Or what exactly – Lino Jun 03 '21 at 11:50
-
1@Lino Thanks for reply. I mean Alpha-2 codes on [this](https://www.iban.com/country-codes) page. – Jack Jun 03 '21 at 11:57
-
Time zones are **time specific** and I don't think that it's possible to retrieve countries' profiles. Check this out: https://stackoverflow.com/questions/3489460/how-to-get-visitors-location-i-e-country-using-geolocation – Jun 03 '21 at 11:56
1 Answers
1
No, you can't get the country code of a time zone.
Although the information is available in the $JRE_HOME$\lib\tzmappings
file, there is no API making the information available to Java code. Also, the information seems to be incomplete in Java 11 and earlier.
You have to keep your own time zone "database" (just a flat file) for that information.

Andreas
- 154,647
- 11
- 152
- 247
-
Thanks for reply. What about using a 3rd party library e.g. **[timezonemap](https://github.com/dustin-johnson/timezonemap)** instead of keeping lots of values in db or *.yml file? I tested [timezonemap](https://github.com/dustin-johnson/timezonemap) and the only problem it may take too much time to search everywhere when I need US and Australia. When giving a region for min-max lat/long, it is fast. What would you suggest from these options? Or another opt? – Jack Jun 03 '21 at 21:40
-
-
-
@Rosa [**Questions asking us to recommend or find a** book, tool, **software library**, tutorial or other off-site resource **are off-topic** for Stack Overflow](https://stackoverflow.com/help/on-topic). – Andreas Jun 04 '21 at 13:10