我使用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?
更多推荐
发布评论