我的代码中遇到了一个恼人的问题。
我希望输出日期如下:
document.getElementById("nights").value = diff + " nights"; {
$('#arrival').datepicker().val();
$('#departure').datepicker().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> '));
};
我在哪里可以更改输出格式?
答案 0 :(得分:1)
在while
循环中,尝试:
while (end > currentDate) {
var month = currentDate.getMonth() + 1;
var day = currentDate.getDate();
var year = currentDate.getUTCFullYear();
between.push(month + '-' + day + '-' + year);
currentDate.setDate(currentDate.getDate() + 1);
}
看起来你正在做更多这些:new Date(variable)
而不是必要的。