//創(chuàng)建date
var nowDate = new Date();
//添加天數(shù)
nowDate.setDate(nowDate.getDate() + 1);
//添加周 添加周用添加天的方式,來添加七天,即為一周
nowDate.setDate(nowDate.getDate() + 7);
//添加月數(shù)
nowDate.setMonth(nowDate.getMonth() + 1);
//添加年數(shù)
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}`);
發(fā)表評論