Add two dates times together in javascript

前端 未结 2 1390
無奈伤痛
無奈伤痛 2021-01-18 02:16

I am trying to add two dates:

date start Fri Apr 26 2013 16:08:03 GMT+0100 (Paris, Madrid)
+  
date periode Fri Apr 26 2013 00:10:00 GMT+0100 (Paris, Madrid         


        
2条回答
  •  野的像风
    2021-01-18 02:52

    Convert datePeriod to milliseconds instead of making it into a date object for your addition.

    You need to convert the sum to a date. getTime() is in milliseconds since 1-1-1970. So you want to do.

    var ending = new Date();
    ending.setTime(dateEnd);
    console.log(ending);
    

    setTime will set the date properly for you.

    https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/setTime

提交回复
热议问题