How can I calculate the time between 2 Dates in typescript

后端 未结 5 1795
傲寒
傲寒 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:32

    In order to calculate the difference you have to put the + operator,

    that way typescript converts the dates to numbers.

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

    From there you can make a formula to convert the difference to minutes or hours.

提交回复
热议问题