其他分享
首页 > 其他分享> > JS 获取最近最近(前)3天日期

JS 获取最近最近(前)3天日期

作者:互联网

//获取最近3天日期
getDay(0);//当天日期
getDay(-3);//3天前日期
function getDay(day){
  var today = new Date();
  var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
  today.setTime(targetday_milliseconds); //注意,这行是关键代码
  var tYear = today.getFullYear();
  var tMonth = today.getMonth();
  var tDate = today.getDate();
  tMonth = doHandleMonth(tMonth + 1);
  tDate = doHandleMonth(tDate);
  return tYear+"-"+tMonth+"-"+tDate;
}
function doHandleMonth(month){
  var m = month;
  if(month.toString().length == 1){
    m = "0" + month;
  }
  return m;
}
View Code

参考博文:https://www.cnblogs.com/luorende/p/9679962.html

标签:tMonth,doHandleMonth,tDate,JS,日期,最近,var,month,today
来源: https://www.cnblogs.com/daytoy105/p/16655948.html