Is it possible to list available TimeZones by Locale in Java?

后端 未结 3 1416
迷失自我
迷失自我 2021-01-20 01:33

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

相关标签:
3条回答
  • 2021-01-20 02:11

    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?

    0 讨论(0)
  • 2021-01-20 02:20

    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.

    0 讨论(0)
  • 2021-01-20 02:29

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

    0 讨论(0)
提交回复
热议问题