// 旦前 含时分秒
function getNowFormatDate() {
let date = new Date()
let seperator1 = "-"
let seperator2 = ":"
let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1
let strDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate()
let currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
+ " " + date.getHours() + seperator2 + date.getMinutes()
+ seperator2 + date.getSeconds()
return currentdate
}
console.log(getNowFormatDate())//2020-12-25 13:41:41
//昨天的时间
var day1 = new Date();
day1.setTime(day1.getTime()-24*60*60*1000);
var s1 = day1.getFullYear()+"-" + (day1.getMonth()+1) + "-" + day1.getDate();
//今天的时间
var day2 = new Date();
day2.setTime(day2.getTime());
var s2 = day2.getFullYear()+"-" + (day2.getMonth()+1) + "-" + day2.getDate();
//明天的时间
var day3 = new Date();
day3.setTime(day3.getTime()+24*60*60*1000);
var s3 = day3.getFullYear()+"-" + (day3.getMonth()+1) + "-" + day3.getDate();
// 新方法 获得 昨天 明天等
//昨天的时间
var day1 = new Date();
day1.setDate(day1.getDate() - 1);
var s1 = day1
//前天的时间
var day2 = new Date();
day2.setDate(day2.getDate() - 2);
var s2 = day2
//明天的时间
var day3 = new Date();
day3.setDate(day.getDate() + 1);
var s2 = day3