isYesterday(time) {
//昨天
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const today = `${year}/${month}/${day}`;
const todayTime = new Date(today).getTime(); // 当天凌晨的时间
const yesterdayTime = new Date(todayTime - 24 * 60 * 60 * 1000).getTime(); // 昨天凌晨的时间
return time < todayTime && yesterdayTime <= time;
},
isToday(date) {
//今天
var d = new Date(date.toString().replace(/-/g,"/"));
var todaysDate = new Date();
if(d.setHours(0,0,0,0) == todaysDate.setHours(0,0,0,0)){
return true;
} else {
return false;
}
},
isLastYear(time){
//去年
const year = new Date().getFullYear();
const lastYear = new Date(time).getFullYear();
return (year - lastYear) === 1;
},
isThisYear(time) {
//今年非昨天
var tYear=new Date().getFullYear()
var tYearTime = new Date(tYear, 0, 1).getTime(); //今年第一天
console.log(tYearTime)
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const today = `${year}/${month}/${day}`;
const todayTime = new Date(today).getTime(); // 当天凌晨的时间
const yesterdayTime = new Date(todayTime - 24 * 60 * 60 * 1000).getTime(); // 昨天凌晨的时间
console.log(yesterdayTime)
return time >= tYearTime && time < yesterdayTime;
},