小编典典

JavaScript-获取两个日期之间的分钟

javascript

如果我有两个日期,我该如何使用JavaScript以分钟为单位获取两个日期之间的差额?


阅读 374

收藏
2020-05-01

共1个答案

小编典典

您可以签出以下代码:

var today = new Date();

var Christmas = new Date("2012-12-25");

var diffMs = (Christmas - today); // milliseconds between now & Christmas

var diffDays = Math.floor(diffMs / 86400000); // days

var diffHrs = Math.floor((diffMs % 86400000) / 3600000); // hours

var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes

alert(diffDays + " days, " + diffHrs + " hours, " + diffMins + " minutes until Christmas 2009 =)");

var diffMins = Math.floor((...舍弃秒,如果您不想舍入分钟。

2020-05-01