我有这个javascript用于自动设置日期过滤器到上个月的第一天和最后一天:
$(document).ready(function () {
$("#DateFrom").datepicker({ dateFormat: 'dd/mm/yy' });
$("#DateTo").datepicker({ dateFormat: 'dd/mm/yy' });
var now = new Date();
var firstDayPrevMonth = new Date(now.getYear(), now.getMonth() - 1, 1);
var firstDayThisMonth = new Date(now.getYear(), now.getMonth(), 1);
var lastDayPrevMonth = new Date(firstDayThisMonth - 1);
$("#DateFrom").datepicker("setDate", firstDayPrevMonth);
$("#DateTo").datepicker("setDate", lastDayPrevMonth);
});
Run Code Online (Sandbox Code Playgroud)
但是now.getYear()返回111而不是预期的2011年.有什么明显的我错过了吗?