JS 计算时间范围,最近一周、一个月



//
最近一周 getDay(-7) 返回的是距离当前日期的一周后的时间
//一月 getDay(-30)
//一年 getDay(-365)
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; }

参考链接:https://www.cnblogs.com/luorende/p/9679962.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM