如何将当前月份日期更改为另一个月 [英] How to change current month date to another month

查看:389
本文介绍了如何将当前月份日期更改为另一个月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择任何日期并将其转换为下一个下个月的相同日期.例如-我选择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 );

});

这篇关于如何将当前月份日期更改为另一个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆