本文介绍了如何提供优雅的时区选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:我倾向于从维基百科中提取数据并自己创建选择器:按国家/地区划分的时区列表按国家/地区划分的夏令时.它仍然存在一些问题:我没有得到所有时区的官方名称,我必须自己提供夏令时.提供不同的语言也可能是个问题.

Update: I lean towards extracting data from Wikipedia and creating the picker myself: List of time zones by country and daylight saving time by country. It still has some issues: I don't get all official names of the time zones and I have to provide for daylight saving times myself. Also providing different languages might be a problem.

我希望我的网站的用户能够选择他们的时区(或者实际上也使用带有他们自己时区以外的时区的网站).我目前使其可行的想法是让用户首先选择他们的国家,然后提供该国家/地区的时区列表以供选择.(选择国家/地区是可选的,如果没有国家/地区,则会有所有可用时区的列表可供选择).

I want the users of my web site to be able to pick their time zone (or in fact also use the site with time zones other than their own). My current idea to make it feasible is to make the user select their country first, then offer a list of time zones from that country to select. (Selecting the country would be optional, without the country there would be a list of all available time zones to choose from).

网络上的所有内容都指向 Olson 数据库,但我遇到了问题.我更愿意显示一个国家的官方时区,而不是奇怪的奥尔森名字.例如,根据 美国时区的维基百科,美国官方有 9 个时区,但 Olson 数据库似乎为美国提供至少 31 个时区.总的来说,我认为 Olson 数据库有太多条目,我不清楚如何将它们归结为官方时区.

Everything on the web points to the Olson database, but I have issues with it. I would prefer to display the official time zones for a country, not the weird Olson names. For example according to Wikipedia on US time zones the USA officially has 9 timezones , but the Olson database seems to provide at least 31 time zones for the US. Overall I think the Olson database has way too many entries, and it is not clear to me how to boil them down to the official time zones.

我也不太喜欢基于地图的选择器的解决方案,因为不是每个人都知道他们在地图上的当前位置.

I don't like the solution of a map based picker very much, either, because not everybody might be aware of their current location on the map.

当然我会提供自动定位,但这只是一个很好的补充.对于想要获取与自己时区不同时区的数据的用户来说,这也无济于事.

Of course I will offer automatic location, but that is only a nice to have add on. Also it wouldn't help for users who want to get data for a different time zone than their own.

非常感谢您提供任何想法!

Many thanks in advance for any ideas!

我接受我可能必须通过地理.但是我怎么能从 Olson 名字中得到一个官方的时区名字呢?我想我可以通过地理找到奥尔森时区,但我不想在我的应用中显示诸如时区:美国/印第安纳州/文森斯"之类的内容).

I accept that I may have to go via geography. But then how could I get an official time zone name from the Olson name? I suppose I could find the Olson time zone via geography, but I don't want to display something like "timezone: America/Indiana/Vincennes" in my app).

(顺便说一句,我当前的应用程序是用 Java 编写的,但我也想了解通用解决方案或可用数据库).

(Incidentally my current app is written in Java, but I would also like to hear about general solutions or available databases).

推荐答案

有一个名为 tzselect 的程序,我相信它是许多不同 Linux 发行版的标准,它可以让您以交互方式选择时区.

There's a program called tzselect, which I believe is standard across many different Linux distributions, that lets you select a timezone interactively.

它首先询问您大陆/海洋,然后是国家,然后是国家内的任何部门(如果有).或者,您可以输入地理坐标并从附近的时区列表中选择一个时区.

It first asks you the continent/ocean, then the country, and then any division within the country if any. Alternatively, you can enter a geographic coordinate and choose a timezone from the list of close ones.

它是用 shell 脚本编写的,你可能想看看源代码,看看它是如何工作的.

It's written in shell script, and you may want to take a look at the source and see how it works.

这篇关于如何提供优雅的时区选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:53