Is the Javascript date object always one day off?

后端 未结 23 2335
既然无缘
既然无缘 2020-11-22 01:49

In my Java Script app I have the date stored in a format like so:

2011-09-24

Now when I try using the above value to create a new Date obje

23条回答
  •  孤街浪徒
    2020-11-22 02:14

    Your issue is specifically with time zone. Note part GMT-0400 - that is you're 4 hours behind GMT. If you add 4 hours to the displayed date/time, you'll get exactly midnight 2011/09/24. Use toUTCString() method instead to get GMT string:

    var doo = new Date("2011-09-24");
    console.log(doo.toUTCString());
    

提交回复
热议问题