我正在使用jQuery datepicker插件。我可以使用下面的代码获取当前月份。我怎样才能得到上个月的名字?
monthName = $.datepicker.formatDate('MM', $("#Calendar").datepicker('getDate'));
请协助。
答案 0 :(得分:0)
试试这个: -
monthName = $.datepicker.formatDate('MM', $("#Calendar").datepicker('getDate').getMonth() - 1);
OR ---------------------------------------------- -------------------------------------------------- -------------------------------
尝试这个工作我自己尝试过:
如图所示取一个数组: -
var months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
和datepicker onSelect将如下所示: -
$('#Calendar').datepicker('option', 'onSelect', function(dateText, inst) { var monthname = months[(dateText.split('/')[1]) - 2]; alert(monthname); }) //we have to subtract '2' instead of '1' because array `months` starts with index '0'.