开发者

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

开发者 https://www.devze.com 2022-12-11 11:13 出处:网络
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.

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?


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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号