Momentjs更改时区而不会影响时间
我正在尝试将时区设置为“瞬间”日期。
我在UTC中得到一个约会:
const date = "2022-01-18T00:00:00.000Z";
我要做下一个时刻区,
moment(date).tz("America/Bogota", true).format();
它应该改变时区而不会影响时间,但我得到了:
2022-01-17T19:00:00-05:00
,我期望的是:
2022-01-18T00:00:00-05:00
I'm trying to set the timezone for a date in moment.js without changing the time value.
I get a date in utc:
const date = "2022-01-18T00:00:00.000Z";
And Im doing the next with moment-timezone
moment(date).tz("America/Bogota", true).format();
It is supposed to change the timezone without affecting the time but im getting:
2022-01-17T19:00:00-05:00
And what I expect:
2022-01-18T00:00:00-05:00
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议也许使用armoent.tz构造函数带有格式字符串。这样,我们将分析输入日期作为当地时间。
I'd suggest perhaps using the moment.tz constructor with a format string. This way, we'll parse the input date as a local time.
我以这种方式修复了:
I fixed this way:
似乎
.format
可能正在将日期转换为本地时间。中获得的各个时区的结果
我在矩
您提供的从UTC转换为当地时间的日期

使用我的本地

moment()
It seems as though
.format
may be converting the date into local time.The results I get with various time zones in moment
The date you provided converted from UTC to my local time

With my local

moment()