The statistics business needs to be processed time weekly: Last week next week, near the week of the month monthly month, and so on need to use time processing so expanded these methods
<! DOCTYPE html>var _datetostring=Date.prototype.toString; Date.prototype.add=function (type, value) {if(!type | | value==undefined| | value==NULL||IsNaN (value)) { Throw"The added type does not exist or the value is not a number" } Switch(type) { Case"D": CaseD: This. SetDate ( This. GetDate () +value); Break CaseM: Case"M": This. Setmonth ( This. GetMonth () +value); Break; CaseY: Case"Y": This. setFullYear ( This. getFullYear () +value); Break; Case"Day": Case"Day": //the day of the weekvar day = This. GetDay () ==0?7: This. GetDay (); var i=Math.Abs (value); if(Value = = 0) { This. Adddate (-(day-1));//this week return; } Value< 0? This. Adddate (-(Day + 7 * i-1)): i > 1? This. Adddate (7-day + ((i-1) * 7) +1): This. Adddate (7-day+1); Break; } var date= This; returndate; } Date.prototype.addDate=function (value) { This. Add ("D", value); } Date.prototype.addMonth=function (value) { This. Add ("M", value); } Date.prototype.addDay=function (value) { This. Add ("Day", value); } Date.prototype.addYear=function (value) { This. Add ("Y", value); } Date.prototype.toString=function (FMT) {if(FMT = =undefined) { return_datetostring.call ( This); } var o= { "m+": This. GetMonth () + 1,//Month"D+": This. GetDate (),//Day"H +": This. GetHours (),//hours"m+": This. getminutes (),//points"S+": This. getseconds (),//seconds"q+": Math.floor (( This. GetMonth () + 3)/3),//Quarterly"S": This. Getmilliseconds ()//milliseconds }; if(/(y+)/.test (FMT)) FMT = Fmt.replace (regexp.$1, ( This. getFullYear () + ""). substr (4-regexp.$1. length)); for(var k in O)if(NewRegExp ("(" + K + ")"). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.length = = 1)? (O[k]): (("XX" + o[k]). substr ("" +o[k])); returnFMT; } var date=NewDate (); //date.adddate (1);//The current time base plus 12 days//date.adddate ( -1);//Current time base minus 12 days//Date.addmonth ( -1);//Current time base minus January//Date.addmonth (1);//Current time base plus January//date.addyear (1);//The current time base plus one year//date.addyear ( -1);//current time base minus one year//Date.addday ( -1);//last week//Date.addday ( -2);//first 2 weeks//date.addday (0);//this week//Console.log (date.tostring ("Yyyy-mm-dd"));//formatted Date//Console.log (date.tostring ()); //Date.addday ( -1);//next week</script>
JS Daily newspaper Weekly report time extension JS