我只需要选择日、月和年(分别),然后计算到期日。为什么这不能正常工作?我使用substr
正确吗?
http://jsfiddle.net/infatti/XeqPT/15/
function daysUntil(year, month, day) {
var now = new Date(),
dateEnd = new Date(year, month - 1, day), // months are zero-based
days = (dateEnd - now) / 1000/60/60/24; // convert milliseconds to days
return Math.round(days);
}
$('#paging1 ul li').each(function () {
var monthDue = $(this).find('.due-date').text().substr(0,2);
var dayDue = $(this).find('.due-date').text().substr(3,2);
var yearDue = $(this).find('.due-date').text().substr(6,4);
$(this).find('.days-due').text(daysUntil(yearDue, monthDue, dayDue));
});