首页 > Web开发 > 详细

js 累加月

时间:2015-03-24 12:32:37      阅读:180      评论:0      收藏:0      [点我收藏+]
    function dateOperator(date,days,operator){
                date = date.replace(/-/g,"/"); //更改日期格式
                var nd = new Date(date);
                var k = parseInt(days) +parseInt(nd.getMonth());
                nd.setMonth(k);
                if(nd.getMonth() + 1<10){
                    if(nd.getDate()<10){
                        return nd.getFullYear() + "-0"+ (nd.getMonth()+1)+"-0"+nd.getDate();
                    }
                    return nd.getFullYear() + "-0"+ (nd.getMonth()+1)+"-"+nd.getDate();
                }
                if(nd.getDate()<10){
                    return nd.getFullYear() + "-0"+ (nd.getMonth()+1)+"-0"+nd.getDate();
                }
                return nd.getFullYear() + "-"+ (nd.getMonth()+1)+"-"+nd.getDate();
            }

参数:

  date:表示日期;可以为字符串;

  days:月份;

  operator:操作方式可不传

使用:dateOperator("2015-01-01",4,"+")

  返回值为:2015-05-01

  

js 累加月

原文:http://www.cnblogs.com/babyhhcsy/p/4362123.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!