moment.js时区不一致(moment.js timezone inconsistency)

编程入门 行业动态 更新时间:2024-10-26 06:39:36
moment.js时区不一致(moment.js timezone inconsistency)

我使用momentjs格式化给定日期。 以下在不同时区的行为有所不同:

moment(new Date("2016" + "-" + "06" + "-01").toISOString()).format('MMMM YYYY')

它给了我May 2016年May 2016在美国/丹佛的时区和June 2016年June 2016在亚洲/卡拉奇。 我通过将浏览器时区更改为不同的时区来进行测试。 它应该是June 2016年June 2016 。

当我将new Date()的格式更改为使用斜杠而不是下面的连字符时,它会在两个时区(即May 2016给出正确的结果。

moment(new Date("2016" + "/" + "06" + "/01").toISOString()).format('MMMM YYYY')

两者似乎都是有效的ISO字符串,会导致这种不一致吗?

I am formatting a given date using momentjs. The following behaves differently in different timezones:

moment(new Date("2016" + "-" + "06" + "-01").toISOString()).format('MMMM YYYY')

It gives me May 2016 in timezone of America/Denver and June 2016 in Asia/Karachi. I tested by changing the browser timezone to different timezones. It should be June 2016 in both.

When i change the format in new Date() to use slashes instead of hyphens like below, it gives me correct result in both timezones i.e. May 2016.

moment(new Date("2016" + "/" + "06" + "/01").toISOString()).format('MMMM YYYY')

Both seem to be valid ISO strings, what would cause this inconsistency?

更多推荐

本文发布于:2023-07-29 20:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319528.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时区   js   moment   timezone   inconsistency

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!