如何在javascript中获取所有时区的列表 [英] How to get list of all timezones in javascript

查看:524
本文介绍了如何在javascript中获取所有时区的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用react / redux开发一个应用程序,我开始使用库 react-intl 格式化消息和日期。

I am developing an application with react/redux, and I started using library react-intl for formatting messages and dates.

我已经能够以< FormattedDate> 标记显示什么时区它正在使用。

I have already been able to show in a <FormattedDate> tag what timezone it's using.

我希望选择现有的所有可能时区,因此当用户选择一个时区时,< FormattedDate> 自动更改该格式。

I would like to have in a select all the possible timezones existing, so when the user picks one timezone, the <FormattedDate> changes to that format automatically.

我没有找到如何用react-intl列出所有可用的时区。

I don't find how to list all posible timezones with react-intl.

我也在谷歌搜索过,我没有找到任何内置的javascript函数。

I have also searched in google, and I did not find any built-in javascript function that does that.

是这样的吗?我怎样才能获得该清单?

Is it that way? How can I obtain that list?

谢谢

注意:不要认为它是同一个问题,因为我不想使用外部库,如果可能的话,如果它是唯一的解决方案,那么我将不得不处理这种方式...:/

Note: Don't think its the same question, since I don't want to use external libraries, if possible, if its the only solution then I will have to handle that way... :/

推荐答案

react-intl库的时区功能完全由 ECMAScript国际化API 功能已集成到浏览器中。

The react-intl library's time zone functionality is provided exclusively by the ECMAScript Internationalization API features that are integrated into the browser.

虽然IANA时区支持是此规范的一部分,但它目前仅涵盖两种情况:

While IANA time zone support is part of this spec, it currently only covers two scenarios:


  • Date 对象格式化为字符串,转换为特定字符串过程中的时区。

  • Formating a Date object to a string, converting to a specific time zone in the process.

确定用户的本地时区标识符。

Determining the user's local time zone identifier.

不幸的是,规范没有定义枚举可用列表的函数e时区。

Unfortunately, there is no function defined by the spec for enumerating the list of available time zones.

此外,请注意,对它所拥有的两个功能的支持目前仅限于少数浏览器。可能需要一段时间才能依赖这些功能。 ECMAScript兼容性表显示了支持的浏览器。在 DateTimeFormat 下,您将找到resolvedOptions()。timeZone默认为主机环境接受IANA时区名称跟踪这些功能。

Additionally, note that support for the two functions it does have is currently limited to a handful of browsers. It will likely be quite some time before these capabilities can be depended upon. The ECMAScript Compatibility Table shows which browsers are supported. Under DateTimeFormat you'll find "resolvedOptions().timeZone defaults to the host environment" and "accepts IANA timezone names" that track these features.

这篇关于如何在javascript中获取所有时区的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆