How can I calculate the time between 2 Dates in typescript

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

    Use the getTime method to get the time in total milliseconds since 1970-01-01, and subtract those:

    var time = new Date().getTime() - new Date("2013-02-20T12:01:04.753Z").getTime();
    

提交回复
热议问题