How can I calculate the time between 2 Dates in typescript

后端 未结 5 1790
傲寒
傲寒 2021-01-31 06:54

This works in Javascript

new Date()-new Date(\"2013-02-20T12:01:04.753Z\")

But in typescript I can\'t rest two new Dates

Date(\         


        
5条回答
  •  醉话见心
    2021-01-31 07:17

    This is how it should be done in typescript:

    (new Date()).valueOf() - (new Date("2013-02-20T12:01:04.753Z")).valueOf()
    

    Better readability:

          var eventStartTime = new Date(event.startTime);
          var eventEndTime = new Date(event.endTime);
          var duration = eventEndTime.valueOf() - eventStartTime.valueOf();
    

提交回复
热议问题