Display users local zone abbreviation(显示用户本地区域缩写)
问题描述
我试图在格式中使用 z 或 zz 来在字符串末尾显示时区,但发现它已被弃用.Z 和 ZZ 可以显示 -0700,但我希望它显示 PDT.
I was trying to use z or zz in format to display the timezone at the end of the string and found that it's deprecated. Z and ZZ work to display -0700, but instead I want it to show PDT.
我得到了 moment-timezone 和数据文件,但我不知道如何使用它来确定客户端的本地时区并显示如下内容:
I got moment-timezone and the data file, but I can't figure out how to use it to determine the client's local time zone and display something like:
2014-05-30T22:56:23.967 太平洋时间
2014-05-30T22:56:23.967 PDT
代替:
2014-05-30T22:56:23.967
2014-05-30T22:56:23.967
是否可以使用 moment-timezone 来确定 EST、CST、MST、PST 等?
Is it possible to use moment-timezone to determine EST, CST, MST, PST, etc?
推荐答案
从 moment-timezone 0.1.0 开始,您可以使用 格式化添加获取特定时区的缩写:
As of moment-timezone 0.1.0, you can use the formatting additions to get the abbreviation of a specific time zone:
moment().tz("America/Los_Angeles").format('z'); // PST or PDT
从 0.5.0 版开始,您现在可以猜测用户的本地时区,当与上述技术结合使用时,您可以执行以下操作:
As of version 0.5.0, you can now guess the user's local time zone, which when combined with the above technique, allows you to do the following:
moment().tz(moment.tz.guess()).format('z');
假设猜测正确,它将显示相关的缩写.
Assuming the guess was correct, it will display the associated abbreviation.
这篇关于显示用户本地区域缩写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:显示用户本地区域缩写
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
