jQuery.datePicker - 计算天数

时间:2009-05-12 22:31:35

标签: jquery datepicker

HY!

我正在使用Kelvin Luck的jquery.datePicker示例。 (http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerClickInput.html

如何计算Date1和Date2之间的天数?

伙计们!

2 个答案:

答案 0 :(得分:2)

这样的事情:

function returnNumberOfDaysBetweenTwoDates(input1, input2) {
    var date1 = new Date(input1.value);
    var date2 = new Date(input2.value);

    var minutes = 1000*60;
    var hours = minutes*60;
    var days = hours*24;

    var diff = Math.abs(date1.getTime() - date2.getTime());

    return round(diff / days);
}

答案 1 :(得分:1)

不要忘记函数名称Math。:

return Math.round(diff / days);