js 获取多少天前
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);