zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js 获取多少天前

JS 获取 多少 天前
2023-09-14 09:06:33 时间
getBeforeDate: function(day, str) {
var now = new Date().getTime(); //获取毫秒数
var before = new Date(now - ((day > 0 && day ? day : 0) * 86400 * 1000));
var year = before.getFullYear();
var month = before.getMonth()+1;
var date = before.getDate();
return year + (str ? str : '-') + (month < 9 ? '0' + month : month) + (str ? str : '-') + (date < 9 ? '0' + date : date)
}

 

  

 

七天前

getBeforeDate(7);

一个月前

getBeforeDate(30);