同一设定的时间在MomentJs时区中返回两个不同的日期?
即使我在 moment.js 时区中为时间设置的值相同,以下两种不同的方法返回的日期值也是不同的
moment("02:00","HH:mm").tz('America/芝加哥').format()
返回 2022-03-31T15:30:00-05:00
moment().tz('America/Chicago').set({hour:"02",min:"00"})
返回 2022-04-01T02:00:02- 05:00
谁能帮我理解为什么会这样?
console.log(moment("02:00","HH:mm").tz('America/Chicago').format());
console.log(moment().tz('America/Chicago').set({hour:"02",minute:"00"}).format());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.34/moment-timezone-with-data-10-year-range.js"></script>
Even the value I set for the time in the moment.js timezones same following two different approaches the value of the date returned is different
moment("02:00","HH:mm").tz('America/Chicago').format()
returns 2022-03-31T15:30:00-05:00
moment().tz('America/Chicago').set({hour:"02",minute:"00"})
returns 2022-04-01T02:00:02-05:00
Can anyone please help me in understanding why is it so?
console.log(moment("02:00","HH:mm").tz('America/Chicago').format());
console.log(moment().tz('America/Chicago').set({hour:"02",minute:"00"}).format());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.34/moment-timezone-with-data-10-year-range.js"></script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过两个示例采用不同的方法:
在第一个示例中,您执行以下操作:
2021-04-01 12:15
)2021-04-01 02:00
)+02:00
tz 到-05:00
- 向后移动 7 小时)(2021-03-31 15:00
)您执行的第二个示例:
2021-04-01 12:15
)2021-04-01 06:15
)02:00
(2021-04-01 02 :00
)You have different approach with two examples:
In first example you do:
2021-04-01 12:15
)2021-04-01 02:00
)+02:00
tz to-05:00
- moves back by 7 hours) (2021-03-31 15:00
)While in second example you do:
2021-04-01 12:15
)2021-04-01 06:15
)02:00
(2021-04-01 02:00
)