js获取当前时间或者n天后的时间
2021-03-19 13:24
标签:gettime nbsp 时间 turn new time() class style enum 函数 调用 js获取当前时间或者n天后的时间 标签:gettime nbsp 时间 turn new time() class style enum 原文地址:https://www.cnblogs.com/xihailong/p/12756068.htmlgetDateXHL(num) {
var date = new Date();
var dateNumber = date.getTime();
var differ = num * 24 * 60 * 60 * 1000;
var needDateNumber = new Date(dateNumber + differ);
var year = needDateNumber.getFullYear();
var month = needDateNumber.getMonth() + 1;
var day = needDateNumber.getDate();
var monthX = month month : month;
var dayX = day day : day;
var nowDate = year + "-" + monthX + "-" + dayX;
return nowDate;
}
//获取7天之前日期
var aaa = getDateXHL(-7);
//获取当前日期
var bbb = getDateXHL(0);
//获取30天之后日期
var ccc = getDateXHL(30);