将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
最佳答案
AFAIK使用_d
之类的内部组件可能会导致意外结果。尝试使用公共API:
moment.tz(...).toDate().toUTCString()
关于javascript - 使用MomentJS将时区特定时间转换为UTC,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38359993/