This question already has answers here:
Why does Javascript getYear() return 108?
(14个回答)
3年前关闭。
我有这个JavaScript,可将日期过滤器自动设置为上个月的第一天和最后一天:
但是
(14个回答)
3年前关闭。
我有这个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);
});
但是
now.getYear()
返回111,而不是预期的2011。我是否错过了明显的事情? 最佳答案
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/getYear