如何使用MOMM JS获得UTC时间的当前时间
I have the following list of array that populates world timezones
how do i get whats the actual time based on what a user selected.
if the user selects the first option (UTC-12:00) International Date Line West how do i get the current time ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
时刻timezone
,我们可以调用<代码> Moment.TZ(TimeZone)在该时区中获取时间。但是,时刻需要一个iana timezone
您有一个Windows的列表时带。
我们可以使用软件包
windows-windows-iana
,i 've创建了一个函数findianatimezone()
,该为Windows时区找到了相应的IANA时区。在这种情况下,我们将在下面的示例中找到等效的IANA时区,然后使用Moment.TZ()在该时区中获取当前时间。
nb:我们不能简单地将UTC偏移添加到一个时区,因为这将因一年中的时间而异。
You can get the time in another timezone using
Moment Timezone
, we can callmoment.tz(timezone)
to get the time in that timezone. However moment requires anIANA timezone
and you have a list of Windows timezones.We can convert using the package
windows-iana
, I've created a functionfindIANATimezone()
that finds the corresponding IANA timezone for a Windows timezone.In this case, we'll find the equivalent IANA timezone for the examples below, then use moment.tz() to get the current time in that timezone.
NB: We can't simply add the UTC offset for a timezone, since this will vary by the time of year.