Pet*_*ran 4 javascript momentjs
我需要创建一个具有以下值的选择,
Eastern Standard Time (EST, GMT-5:00)
Central Standard Time (CST, GMT-6:00)
Mountain Standard Time (MST,GMT-7:00)
Phoenix Standard Time (PNT, GMT-7:00)
Pacific Standard Time (PST, GMT-8:00)
Run Code Online (Sandbox Code Playgroud)
有没有办法通过moment.js来做到这一点?
moment.js通过moment-timezone提供时区支持,因此如果你加载了整套时区,你可以通过迭代来过滤你关心的时区moment.tz.names(),然后调用format("z, Z")以获得你想要的字符串.
> moment.tz("America/Los_Angeles").format("z, Z")
"PDT, -07:00"
> moment.tz("2016-01-01", "America/Los_Angeles").format("z, Z")
"PST, -08:00"
Run Code Online (Sandbox Code Playgroud)