admin管理员组文章数量:1435859
I use the method toISOString()
to convert a date into a ISO String
console.log(date);
var x = date.toISOString();
console.log(x);
My input date-object contains the following data
Wed Apr 01 2020 01:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)
The output of toISOString()
is 2020-03-31T23:00:00.000Z
I try to find a solution and explaination about this strange result, because it happens only by the 1st of April - and this is not an april joke. Does somebody can explain the behavior? Or can give me a hint, how I can get the correct value?
I use the method toISOString()
to convert a date into a ISO String
console.log(date);
var x = date.toISOString();
console.log(x);
My input date-object contains the following data
Wed Apr 01 2020 01:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)
The output of toISOString()
is 2020-03-31T23:00:00.000Z
I try to find a solution and explaination about this strange result, because it happens only by the 1st of April - and this is not an april joke. Does somebody can explain the behavior? Or can give me a hint, how I can get the correct value?
Share Improve this question asked Feb 28, 2018 at 14:28 michael-mammutmichael-mammut 2,8035 gold badges31 silver badges49 bronze badges 6- How is Date set? – epascarello Commented Feb 28, 2018 at 14:30
- 2 Different timezones, but the date is the same. – Federico klez Culloca Commented Feb 28, 2018 at 14:31
- So what's the problem? The ISO string is in UTC while your input date is in GMT+2. They are the same date. – Derek 朕會功夫 Commented Feb 28, 2018 at 14:31
- There is no problem, both represent exactly the same instant in time, just with different offsets to UTC – phuzi Commented Feb 28, 2018 at 14:32
- 1 “because it happens only by the 1st of April - and this is not an april joke. Does somebody can explain the behavior?” - you might want to go check when DST ends in 2020 ... – C3roe Commented Feb 28, 2018 at 14:32
1 Answer
Reset to default 9Simple.
Your timezone is +0200 GMT
, and toISOString()
gives you Zulu
time. Everything is correct here.
本文标签: javascripttoISOString() return the wrong data at first aprilStack Overflow
版权声明:本文标题:javascript - toISOString() return the wrong data at first april - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745669227a2669470.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论