使用Moment.js显示用户本地区域缩写 [英] Using Moment.js to display the users local zone abbreviation

查看:627
本文介绍了使用Moment.js显示用户本地区域缩写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在格式中使用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.

我有时间 - 时区和数据文件,但我无法弄清楚如何使用它来确定客户的本地时区并显示如下内容:

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 PDT

2014-05-30T22:56:23.967 PDT

而不是:

2014-05-30T22:56:23.967

2014-05-30T22:56:23.967

是吗可以使用时刻 - 时区确定EST CST ... MST PST?

Is it possible to use moment-timezone to determine EST CST ... MST PST?

推荐答案

截至时刻时区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.

这篇关于使用Moment.js显示用户本地区域缩写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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