如何计算打字稿中2个日期之间的时间 [英] How can I calculate the time between 2 Dates in typescript

查看:32
本文介绍了如何计算打字稿中2个日期之间的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这适用于Java语言

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

但是在打字稿中,我不能休息两个新的日期

But in typescript I can't rest two new Dates

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

无效,因为参数与日期签名不匹配

Don't work because paremater not match date signature

推荐答案

使用 getTime 方法,以获取自1970年1月1日以来的总时间(以毫秒为单位),并减去这些时间:

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();

这篇关于如何计算打字稿中2个日期之间的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆