本文介绍了Javascript date.getYear()在2011年返回111?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$(文件).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);
});
BUT now.getYear()
正在返回111而不是预期的。有没有什么明显的我错过了?
解决方案
I have this javascript for automatically setting a date filter to the first and last day of the previous month:
$(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);
});
BUT now.getYear()
is returning 111 instead of the expected 2011. Is there something obvious I've missed?
解决方案
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/getYear
这篇关于Javascript date.getYear()在2011年返回111?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!