//创建date
var nowDate = new Date();
//添加天数
nowDate.setDate(nowDate.getDate() + 1);
//添加周 添加周用添加天的方式,来添加七天,即为一周
nowDate.setDate(nowDate.getDate() + 7);
//添加月数
nowDate.setMonth(nowDate.getMonth() + 1);
//添加年数
nowDate.setYear(nowDate.getFullYear() + 1);
打印格式为年月日时分秒
const year = nowDate.getFullYear();
const month = (nowDate.getMonth() + 1).toString().padStart(2, '0');
const day = nowDate.getDate().toString().padStart(2, '0');
const hours = nowDate.getHours().toString().padStart(2, '0');
const minutes = nowDate.getMinutes().toString().padStart(2, '0');
const seconds = nowDate.getSeconds().toString().padStart(2, '0');
console.log(`${year}-${month}-${day} ${hours}:${minutes}:${seconds}`);
发表评论