日期添加多个月

1 function addMoth(d,m){
2    var ds=d.split('-'),_d=ds[2]-0;
3    var nextM=new Date( ds[0],ds[1]-1+m+1, 0 );
4    var max=nextM.getDate();
5    d=new Date( ds[0],ds[1]-1+m,_d>max? max:_d );
6    return d.toLocaleDateString().match(/\d+/gadd).join('-')
7 }
8 addMoth('2017-1-31', 1)

猜你喜欢

转载自www.cnblogs.com/mxyr/p/9238319.html