//获取时间
getTime() {
var getNowDate = new Date();
//获取当前日期时间
const nowYear = getNowDate.getFullYear();
let nowMonth = getNowDate.getMonth() + 1;
let nowDay = getNowDate.getDate();
if (nowMonth >= 1 && nowMonth <= 9) {
nowMonth = "0" + nowMonth;
}
if (nowDay >= 1 && nowDay <= 9) {
nowDay = "0" + nowDay;
} else if (nowDay == 1) {
nowDay = 30;
nowMonth -= 1;
}
var nowDate = nowYear + "-" + nowMonth + "-" + nowDay;
//获取一周时间
var getOneweek = new Date(getNowDate - 7 * 24 * 3600 * 1000);
var thYear = getOneweek.getFullYear();
var thMonth = getOneweek.getMonth() + 1;
var thDay = getOneweek.getDate();
if (thMonth >= 1 && thMonth <= 9) {
thMonth = "0" + thMonth;
}
if (thDay >= 0 && thDay <= 9) {
thDay = "0" + thDay;
}
var oneweekDate = thYear + "-" + thMonth + "-" + thDay;
//获取一个月前时间
getNowDate.setMonth(getNowDate.getMonth() - 1);
var thirtyYear = getNowDate.getFullYear();
var thirtyMonth = getNowDate.getMonth() + 1;
var thirtyDay = getNowDate.getDate();
if (thirtyMonth >= 1 && thirtyMonth <= 9) {
thirtyMonth = "0" + thirtyMonth;
}
if (thirtyDay >= 1 && thirtyDay <= 9) {
thirtyDay = "0" + thirtyDay;
}
var monthDate = thirtyYear + "-" + thirtyMonth + "-" + thirtyDay;
// 获取三年时间
var date = new Date();
var y = date.getFullYear() - 2; // 减一是算去年时间,+ 1 是明年时间
var dateStr = y + "-" + 1 + "-" + 1;
return {
nowDate: nowDate,
oneweekDate: oneweekDate,
monthDate: monthDate,
dateStr: dateStr,
};
},
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/79151.html