日期前一天前一周前一个月
num(s) {
return s < 10 ? "0" + s : s;
},
day() {
let day = new Date();
day.setTime(day.getTime() - 24 * 60 * 60 * 1000);
let dayOld =
day.getFullYear() +
"-" +
this.num(day.getMonth() + 1) +
"-" +
this.num(day.getDate());
this.staday = dayOld + " " + "00:00:00";
this.endday = dayOld + " " + "24:00:00";
this.dayFalse = "1";
},
week() {
let nowdate = new Date();
nowdate.setTime(nowdate.getTime());
var dayDate =
nowdate.getFullYear() +
"-" +
this.num(nowdate.getMonth() + 1) +
"-" +
this.num(nowdate.getDate());
let week = new Date(nowdate - 6 * 24 * 3600 * 1000);
let y = week.getFullYear();
let m = week.getMonth() + 1;
let d = week.getDate();
let formatwdate = y + "-" + this.num(m) + "-" + this.num(d);
this.staweek = formatwdate + " " + "00:00:00";
this.endweek = dayDate + " " + "24:00:00";
// console.log(this.staweek, this.endweek);
this.dayFalse = "2";
this.search();
},
month() {
let nowdate = new Date();
nowdate.setMonth(nowdate.getMonth());
let y = nowdate.getFullYear();
let m = nowdate.getMonth() + 1;
let d = nowdate.getDate();
let month = y + "-" + this.num(m) + "-" + this.num(d);
this.endmonth = month + " " + "24:00:00";
this.stamonth = DateDay(nowdate) + " " + "00:00:00";
this.dayFalse = "3";
},
nowMonth() {
var now = new Date(); //当前日期
now.setTime(now.getTime());
var getnowMonthEndDate =
now.getFullYear() +
"-" +
this.num(now.getMonth() + 1) +
"-" +
this.num(now.getDate());
var nowMonth = now.getMonth(); //当前月
var nowYear = now.getYear(); //当前年
nowYear += nowYear < 2000 ? 1900 : 0; //
var monthStartDate = new Date(nowYear, nowMonth, 1);
var getnowMonthStartDate = this.newformatDate(monthStartDate);
this.dayFalse = "2";
this.nowSta = getnowMonthStartDate + " " + "00:00:00";
this.nowEnd = getnowMonthEndDate + " " + "24:00:00";
// console.log(this.nowSta, this.nowEnd);
this.search();
},
getMonthDays(myMonth) {
var now = new Date(); //当前日期
var nowYear = now.getYear(); //当前年
nowYear += nowYear < 2000 ? 1900 : 0;
var monthStartDate = new Date(nowYear, myMonth, 1);
var monthEndDate = new Date(nowYear, myMonth + 1, 1);
var days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24);
return days;
},
newformatDate(date) {
var myyear = date.getFullYear();
var mymonth = date.getMonth() + 1;
var myweekday = date.getDate();
if (mymonth < 10) {
mymonth = "0" + mymonth;
}
if (myweekday < 10) {
myweekday = "0" + myweekday;
}
return myyear + "-" + mymonth + "-" + myweekday;
},
oldMonth() {
var now = new Date(); //当前日期
var nowMonth = now.getMonth(); //当前月
var nowYear = now.getYear(); //当前年
nowYear += nowYear < 2000 ? 1900 : 0; //
var lastMonthDate = new Date(); //上月日期
lastMonthDate.setDate(1);
lastMonthDate.setMonth(lastMonthDate.getMonth() - 1);
var lastYear = lastMonthDate.getYear();
var lastMonth = lastMonthDate.getMonth();
var getLastMonthStartDate = new Date(nowYear, lastMonth, 1);
var getLastMonthStartDate = this.newformatDate(getLastMonthStartDate);
// console.log("上月开始时间" + getLastMonthStartDate);
//获得上月结束时间
var getLastMonthEndDate = new Date(
nowYear,
lastMonth,
this.getMonthDays(lastMonth)
);
var getLastMonthEndDate = this.newformatDate(getLastMonthEndDate);
// console.log("上月结束时间" + getLastMonthEndDate);
this.dayFalse = "1";
this.oldSta = getLastMonthStartDate + " " + "00:00:00";
this.oldEnd = getLastMonthEndDate + " " + "24:00:00";
this.search();
},
不求大富大贵,但求一生平凡