0

I have a locale string like en-GB (got through navigator.language in javascript ) and want to use this to calculate the locale's time zone in the Java.

What is the recommended way to do this. I understand it would not always be accurate to calculate the timezone from locale. But even a guesstimate approach would be fine.

I checked this SO question but they don't recommend any method in Java which would use only the locale string and arrive at approximate timezone. Any library or hacks to get around this ? Because local denotes a particular region and a particular region will always have the same timezone.

AnandShiva
  • 906
  • 11
  • 22
  • 1
    I added [another Answer](https://stackoverflow.com/a/59497070/642706) to that Question you linked. That may help you understand that (a) a `Locale` is not geographical, and (b) `Locale` has nothing to with time zones. Furthermore your wanting to "guesstimate" time zone is *not* a good idea. Either use the user’s current default time zone, or, if crucial to your business logic, confirm the intended time zone with the user. There is no other shortcut. Guessing at time zones is like guessing the currency for a given amount of money – not a proper approach to business. – Basil Bourque Dec 27 '19 at 06:50
  • You can’t. While some locales indicate a country, others do not (for example `Locale.ENGLISH` — English is spoken all over the world). And one country may have a lot of time zones. – Ole V.V. Dec 27 '19 at 13:30

0 Answers0