首先获取字符串格式的日期,然后获取这个日期的时间戳,通过时间戳完成加一天的操作,再将时间戳转换为date格式,再转换为字符串格式。
//增加一天
function addDate(time) {
//加一天
var timestamp = Date.parse(new Date(time));
timestamp = timestamp /1000;
timestamp += 86400;//加一天
var newTime =new Date(timestamp * 1000).format('yyyy-MM-dd hh:mm:ss');
return newTime;
}
//日期格式
Date.prototype.format = function(format) {
var date = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S+": this.getMilliseconds()
};
if (/(y+)/i.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (var k in date) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1
? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
}
}
return format;
}