function 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 getThreeDate = new Date(getNowDate -3*24*3600*1000);
var thYear = getThreeDate.getFullYear();
var thMonth = getThreeDate.getMonth()+1;
var thDay = getThreeDate.getDate();
if(thMonth >= 1 && thMonth <= 9 ){
thMonth = '0' + thMonth
}
if(thDay >= 0 && thDay <=9 ){
thDay = '0' + thDay
}
var thDate = thYear + '-' + thMonth + '-' + thDay;
//获取前七天时间
var getWeekDate = new Date(getNowDate -7*24*3600*1000);
var weekYear = getWeekDate.getFullYear();
var weekMonth = getWeekDate.getMonth()+1;
var weekDay = getWeekDate.getDate();
if(weekMonth >= 1 && weekMonth <=9 ){
weekMonth = '0' + weekMonth
}
if(weekDay >= 1 && weekDay <= 9){
weekDay = '0' + weekDay
}
var weekDate = weekYear + '-' + weekMonth + '-' + weekDay;
//获取一个月前时间
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;
return {'nowDate':nowDate,'thDate':thDate,'weekDate':weekDate,'monthDate':monthDate}
}
js获取前三天,前七天,前一个月的时间
转载文章标签 js 文章分类 JavaScript 前端开发
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
下一篇:jdk环境变量配置
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
mysql 存储过程返回更新前记录
mysql 存储过程返回更新前记录
存储过程 字段 自连接