两个日期之间的差异

时间:2012-12-28 12:51:20

标签: javascript date

我有以下(工作)JavaScript datepicker。 “out”mindate等于1.我怎样才能使“out”注意力等于我的访客在日期和今天的日期之间的差异,而不仅仅是1?

$(function() { var dateSelected = false;

$( "#in" ).datepicker({
    minDate: 0,
    defaultDate: "+1w",
    changeMonth: true,
    numberOfMonths: 3,
    onClose: function(dateText, inst) {
        dateSelected = true;

    }
});

$('form').submit(function(){
    if (!dateSelected) {
        alert('Please Enter start Dates');
    }
    return dateSelected;
});
});

$(function() { var dateSelected = false;


$( "#out" ).datepicker({
    minDate: 1,
    defaultDate: "+1w",
    changeMonth: true,
    numberOfMonths: 3,
    onClose: function(dateText, inst) {
        dateSelected = true;

    }
});
$('form').submit(function(){
    if (!dateSelected) {
        alert('Please Enter end Dates');
    }
    return dateSelected;
});
});

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在这样的日子里得出out和in date之间的差异:

var nDifference = Math.abs(new Date($("#in").val()) - new Date());
var one_day = 1000 * 60 * 60 * 24;
var days = Math.round(nDifference / one_day);

并设置分钟日期,如:

minDate: days;​