将日期范围放入数组

时间:2014-04-05 15:05:40

标签: javascript arrays date datepicker

我的页面上有两个JQuery datepicker,我想把这两个日期之间的所有日子都放到一个数组中。

我该如何解决这个问题? 这是我的片段:

function mennyi() {
var dtFrom = document.getElementById('arrival').value;
var dtTo = document.getElementById('departure').value;
var dt1 = new Date(dtFrom);
var dt2 = new Date(dtTo);
var diff = dt2.getDate() - dt1.getDate();
var days = diff;
alert(dtTo);
document.getElementById("nights").innerHTML = days + " nights"; {
   $('#arrival').datepicker({ dateFormat: 'dd-mm-yy' }).val();
   $('#departure').datepicker({ dateFormat: 'dd-mm-yy' }).val();
var start = new Date(document.getElementById('arrival').value),
    end = new Date(document.getElementById('departure').value),

    currentDate = new Date(start),
    between = []
;

while (end > currentDate) {
    between.push(new Date(currentDate));
    currentDate.setDate(currentDate.getDate() + 1);
}

$('#lista').html(between.join('<br> '));};
return false;
}
function isNumeric(val) {
  var ret = parseInt(val);
};

现在它可以工作,但问题是如何在将字符串放入数组之前更改日期格式?

0 个答案:

没有答案