如何将当前月份日期更改为另一个月
问题描述:
我想选择任何日期并将其转换为下一个下个月的相同日期.例如-我选择2014年6月1日,然后显示2014年7月1日,依此类推.
I want to select any date and convert it to same date of next upcoming month. For example- I select 1st jun 2014 then it show 1st july 2014 and so on..
HTML
<input type='text' id='txtDate' readonly='true' />
<input type='button' id='btnConvert' value='Convert' /><br/>
Current Date : <span id='spnCurrentDate'></span><br/>
Next Month Date : <span id='spnNewDate'></span>
JS
$("#txtDate").datepicker({
changeMonth: true
});
$("#btnConvert").click(function(){
$("#spnCurrentDate").html($("#txtDate").val());
$("#spnNewDate").html($("#txtDate").val());
答
var date1 = new Date();
date1.setMonth(date1 .getMonth() + 1);
现在date1是一个保存一个月后日期的对象
now date1 is an object holding a date which is 1 months later
如果要将其设置为jQuery UI DatePickers,则可以执行此操作
If you want to set it to the jQuery UI DatePickers, you can do this
$("#txtDate").datepicker({
changeMonth: true
});
$("#btnConvert").click(function(){
var date1 = new Date($("#txtDate").val());
date1.setMonth(date1 .getMonth() + 1);
$("#txtDate").datepicker("setDate", date1 );
});