且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在几分钟内获得两个日期之间的差异

更新时间:2023-02-12 17:01:03

转换单位:

var milliseconds = (startdate.getTime() - currentDate.getTime());
var seconds = milliseconds / 1000;
var minutes = seconds / 60;

或者,一体化:

var minutes = (startdate.getTime() - currentDate.getTime()) / 1000 / 60;

这最有可能给你一个大小数。对于舍入,请使用 Math.floor Math.ceil Math.round

This will give you a big decimal most likely. For rounding, use Math.floor, Math.ceil, or Math.round.