Is the Javascript date object always one day off?

后端 未结 23 2635
既然无缘
既然无缘 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:32

    The best way to handle this without using more conversion methods,

     var mydate='2016,3,3';
     var utcDate = Date.parse(mydate);
     console.log(" You're getting back are 20.  20h + 4h = 24h :: "+utcDate);
    

    Now just add GMT in your date or you can append it.

     var  mydateNew='2016,3,3'+ 'GMT';
     var utcDateNew = Date.parse(mydateNew);
     console.log("the right time that you want:"+utcDateNew)
    

    Live: https://jsfiddle.net/gajender/2kop9vrk/1/

提交回复
热议问题