以小时计算时差

时间:2016-02-25 13:10:59

标签: javascript jquery

如何以小时为单位获取当前时间与开始日期之间的小时差异?

var diff = new Date("2016-02-26 17:21:29") - new Date();
diff_time = diff / (60 * 60 * 1000);
//alert(diff_time);

if (diff_time < 24) {
    alert("Please select the start date greater than 24 hours");
}

1 个答案:

答案 0 :(得分:0)

时间格式应为/或空格分隔,而不是-分隔

var diff = new Date($('#start_date').val()) - new Date() ;
diff_time = diff / (60 * 60 * 1000);
alert(diff_time);
return false;

if (diff_time < 24) {
    error = "Please select the start date on";
}