如果我有两个日期,我该如何使用JavaScript以分钟为单位获取两个日期之间的差额?
您可以签出以下代码:
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((...舍弃秒,如果您不想舍入分钟。
var diffMins = Math.floor((...