使用MomentJS将时区特定时间转换为UTC

时间:2016-07-13 19:18:44

标签: javascript datetime momentjs utc

Casablanca时间转换为UTC时,MomentJS使用错误的小时:

moment.tz.add("Africa/Casablanca|LMT WET WEST CET|u.k 0 -10 -10|0121212121212121213121212121212121212121212121212121212121212121212121212121212121212121212121212121|-2gMnt.E 130Lt.E rb0 Dd0 dVb0 b6p0 TX0 EoB0 LL0 gnd0 rz0 43d0 AL0 1Nd0 XX0 1Cp0 pz0 dEp0 4mn0 SyN0 AL0 1Nd0 wn0 1FB0 Db0 1zd0 Lz0 1Nf0 wM0 co0 go0 1o00 s00 dA0 vc0 11A0 A00 e00 y00 11A0 uM0 e00 Dc0 11A0 s00 e00 IM0 WM0 mo0 gM0 LA0 WM0 jA0 e00 Rc0 11A0 e00 e00 U00 11A0 8o0 e00 11A0 11A0 5A0 e00 17c0 1fA0 1a00 1a00 1fA0 17c0 1io0 14o0 1lc0 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1lc0 14o0 1fA0|32e5");


alert(moment.tz({ year: 2016, month: 6, date: 13, hour: 20 }, "Africa/Casablanca")._d.toUTCString());

这显示20:13,但它应该显示19:13(UTC),不应该吗?

JSFIDDLE

1 个答案:

答案 0 :(得分:1)

AFAIK,使用_d等内部结构可能会导致意外结果。尝试使用公共API:

moment.tz(...).toDate().toUTCString()