var registerDateRange = (function(option){ var dateRange = {}; var sysDate = new Date(); switch(option) { case ‘0‘ : break; case ‘1‘ : sysDate.setDate(sysDate.getDate() - (sysDate.getDay() - 1)); dateRange.from = sysDate; break; case ‘2‘ : sysDate.setDate(sysDate.getDate() - (sysDate.getDay() + 6)); dateRange.from = sysDate; var toDate = new Date(); toDate.setDate(sysDate.getDate() + 6); dateRange.to = toDate; break; case ‘3‘ : sysDate.setDate(sysDate.getDate() - (sysDate.getDate() - 1)); dateRange.from = sysDate; break; case ‘4‘ : sysDate.setDate(sysDate.getDate() - sysDate.getDate()); dateRange.to = sysDate; var fromDate = new Date(sysDate); fromDate.setDate(fromDate.getDate() - (fromDate.getDate() - 1) ); dateRange.from = fromDate; break; } return dateRange; })($("#registerDate").val());
this week,last week,this month,last month
原文:http://www.cnblogs.com/shouwangzhe-/p/3986119.html