js月份,日期加一天

js没有直接能够用的函数,因此只能本身写,其中须要涉及到每月天数的判断,若是是2月份的话,还要涉及到闰年的判断函数

 1 var addDate = {
 2         //日期,在原有日期基础上,增长days天数,默认增长1天
 3         setDate:function(date, days){
 4             if (days == undefined || days == '') {
 5                 days = 1;
 6             }
 7             var date = new Date(date);
 8             date.setDate(date.getDate() + days);
 9             var month = date.getMonth() + 1;
10             var day = date.getDate();
11             return date.getFullYear() + '-' + this.getFormatDate(month) + '-' + this.getFormatDate(day);
12         },
13         //日期月份/天的显示,若是是1位数,则在前面加上'0'
14         getFormatDate:function(arg){
15             if (arg == undefined || arg == '') {
16                 return '';
17             }
18             var re = arg + '';
19             if (re.length < 2) {
20                 re = '0' + re;
21             }
22             return re;
23         }
24     }
相关文章
相关标签/搜索