3

I need to generate a list of timezones to display for a user. We'd like to narrow the list down depending on the user's Locale.

If the user has a locale of 'en_US', he probably doesn't care to see 'Asia/Ashkhabad' in the list.

Is this doable?

A.H.
  • 63,967
  • 15
  • 92
  • 126
Eric
  • 757
  • 5
  • 11
  • 1
    `Locale` has nothing to do with time zones, and nothing to do with geography. See [this Question](https://stackoverflow.com/q/10570884/642706). – Basil Bourque Dec 27 '19 at 08:12

3 Answers3

5

No you can't. You can use TimeZone.getAvailableIDs(int rawoffset) to narrow the results, but then you need to keep a map of Locale->raw offsets.

Also, what happens if your user is an American located in India? Don't you want to display the Asia/Kolkata time zone for him?

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
David Rabinowitz
  • 29,904
  • 14
  • 93
  • 125
1

Of course it's doable... but you'll have to write some code.

You'll have to front your time zone selection with code which filters the list of timezones. You'd populate that filter with a map of locales to the set of timezones for the locale.

However, as David noted, you will face the issue of people whose Locale is not their work location or timezone, so be prepared to deal with this in a two-tiered approach, or to pick up "virtual locale" from somewhere.

CPerkins
  • 8,968
  • 3
  • 34
  • 47
-1

You might find THIS useful in implementing what you want to do.

ChadNC
  • 2,528
  • 4
  • 25
  • 39