日期前一周的时间显示:
//时间格式化
function timeFormat() {
var date = new Date(), y = date.getFullYear(), m = date.getMonth() + 1, d = date.getDate(),
nowDate = y + "-" + m + "-" + d;
return nowDate;
}
//当前日期后退一周的时间 时间格式:yyyy-yy-yy
function get7DaysBefore(date){
var date = date || new Date(),
timestamp, newDate;
if(!(date instanceof Date)){
date = new Date(date.replace(/-/g, '/'));
}
timestamp = date.getTime();
newDate = new Date(timestamp - 7 * 24 * 3600 * 1000);
return [newDate.getFullYear(), newDate.getMonth() + 1, newDate.getDate()].join('-');
}