1.计算当前日期后的N天function date2str(n){
var s, d, t, t2;
t = new Date().getTime();
t2 = n * 1000 * 3600 * 24;
t+= t2;
d = new Date(t);
s = d.getUTCFullYear() + "-";
s += ("00"+(d.getUTCMonth()+1)).slice(-2) + "-";
s += ("00"+d.getUTCDate()).slice(-2);
return s;
}
2.计算给定日期后的N天
function str2date(str,n){
var dd, mm, yy;
var reg = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
if (arr = str.match(reg)) {
yy = Number(arr[1]);
mm = Number(arr[2])-1;
dd = Number(arr[3]);
} else {
var d = new Date();
yy = d.getUTCFullYear();
mm = ("00"+(d.getUTCMonth())).slice(-2);
dd = ("00"+d.getUTCDate()).slice(-2);
}
return date2str(yy, mm, dd,n);
}
3.计算给定日期后的N天function date2str(yy, mm, dd,n) {
var s, d, t, t2;
t = Date.UTC(yy, mm, dd);
t2 = n * 1000 * 3600 * 24;
t+= t2;
d = new Date(t);
s = d.getUTCFullYear() + "-";
s += ("00"+(d.getUTCMonth()+1)).slice(-2) + "-";
s += ("00"+d.getUTCDate()).slice(-2);
return s;
}