/**
功能:计算N天前的日期
@params days:天数
@return N天前的日期,"yyyy-MM-dd" 格式
**/
function calDate(days) {
var now = new Date();
if (days >= 1) {
now = new Date(now.getTime() - 86400000 * days); //以毫秒计,1000ms*60s*1H*24H * N天
}
var yyyy = now.getFullYear(), mm = (now.getMonth() + 1).toString(), dd = now.getDate().toString();
if (mm.length == 1) {
mm = "0" + mm;
}
if (dd.length == 1) {
dd = "0" + dd;
}
return (yyyy + "-" + mm + "-" + dd);
}
计算N天前的日期
最新推荐文章于 2024-01-03 14:22:47 发布