問題描述
我試圖在格式中使用 z
或 zz
來在字符串末尾顯示時區(qū),但發(fā)現(xiàn)它已被棄用.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
和數(shù)據(jù)文件,但我不知道如何使用它來確定客戶端的本地時區(qū)并顯示如下內(nèi)容:
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 開始,您可以使用 格式化添加獲取特定時區(qū)的縮寫:
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 版開始,您現(xiàn)在可以猜測用戶的本地時區(qū),當與上述技術(shù)結(jié)合使用時,您可以執(zhí)行以下操作:
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');
假設(shè)猜測正確,它將顯示相關(guān)的縮寫.
Assuming the guess was correct, it will display the associated abbreviation.
這篇關(guān)于顯示用戶本地區(qū)域縮寫的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!