我正在使用jquery datepicker来选择一些日期,但我不想显示当前月份,只是前几个月。我怎么能得到它?
目前我得到了下一个代码,但我如何选择过去几个月的所有日子?
$("#toDate").datepicker({
maxDate: "-1M",
dateFormat: 'dd/mm/yy',
firstDay: 1,
onSelect: function(selected) {
var today = getDate();
alert(today);
$("#fromDate").datepicker("option", "maxDate", selected)
}
});
答案 0 :(得分:1)
据我所知,获取上个月全天的唯一方法是将maxDate设置为上个月的最后一天。
var d = new Date(); // current date
d.setDate(1); // 1st of the month
d.setHours(-1); // one hour before the 1st of the month (last day of previous month)
$("#toDate").datepicker({
maxDate: d,
dateFormat: 'dd/mm/yy',
firstDay: 1,
onSelect: function(selected) {
var today = getDate();
alert(today);
$("#fromDate").datepicker("option","maxDate", selected)
}
});
Js Fiddle:https://jsfiddle.net/ua2oc347/2/