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

时间:2015-11-10 20:00:02

标签: javascript jquery datetime

我有两个日期def is_alpha(your_string): for c in your_string: if c not in ALPHABETS: return False return True startdate

如何区分两个日期以分钟为单位

currentdate

我能够减去这两个日期,但我不确定如何将输出(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 )转换为分钟。

1 个答案:

答案 0 :(得分:3)

转换单位:

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