【问题标题】:Get the Difference Between Two Dates in Minutes在几分钟内获得两个日期之间的差异
【发布时间】:2016-02-11 19:58:47
【问题描述】:

我有两个约会 startdatecurrentdate

我怎样才能得到两个日期之间的差异以分钟为单位

console.log("startdate: " + startdate + " currentdate: " + currentdate);
>> startdate: Tue Nov 10 2015 13:00:00 GMT-0800 (PST) 
>> currentdate: Tue Nov 10 2015 11:55:53 GMT-0800 (PST)

console.log(startdate.getTime() - currentdate.getTime());
>> 3846736

我可以减去这两个日期,但我不确定如何将该输出 (output: 3846736) 转换为分钟。

【问题讨论】:

标签: javascript jquery datetime


【解决方案1】:

换算单位:

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

或者,多合一:

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

这很可能会给你一个大的小数。对于舍入,请使用 Math.floorMath.ceilMath.round

【讨论】:

    猜你喜欢
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    相关资源
    最近更新 更多