Javascript Date.toJSON don't get the timezone offset

前端 未结 2 942
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 14:36

Well the problem is that I was using code like this:

new Date().toJSON().slice(0, 10)

to get my date as YYYY-MM-DD string, the

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 15:02

    I haven't noticed that the toJSON method don't take into account your timezone offset

    But it does, it converts the local-time to Zulu (look at the end of the string: Z)

    new Date( "2012-01-02T03:04:05+02:00" ).toJSON()
    "2012-01-02T01:04:05.000Z"
    

提交回复
热议问题