First, package for the jquery version of the date collection plug-in
Jquery.datecollections = (function(){ varNowdate =NewDate (); varClonenowdate =NewDate (); varFullyear =nowdate.getfullyear (); varmonth = Nowdate.getmonth () + 1;//the GetMonth method returns 0-11, representing January-December varDate =nowdate.getdate (); varEndOfMonth =NewDate (fullyear, month, 0). GetDate ();//get the last day of the month //formatted Date (2016-02-14) functiongetfulldate (targetdate) {vard, Y, M, D; if(targetdate) {D=NewDate (targetdate); Y=d.getfullyear (); M= D.getmonth () + 1; D=d.getdate (); } Else{y=fullyear; M=month; D=date; } m= m > 9? M: ' 0 ' +m; D= d > 9? D: ' 0 ' +D; returnY + '-' + M + '-' +D; } //Timestamp of the day (in milliseconds) varTimestampofday = 1000*60*60*24; //Today, yesterday varFulltoday =getfulldate (); varFullyesterday = Getfulldate (Nowdate-timestampofday); varNowday = Nowdate.getday ();//The GetDay method returns 0 for SundayNowday = Nowday = = = 0? 7: Nowday; //this Monday, the end of the week (Sunday) //Note: Under Safari (Nowdate +-0) is not converted to a timestamp, where the operator + is preceded by the nowdate, and the timestamp operation is manually converted varFullmonday = Getfulldate (+nowdate-(nowDay-1) *timestampofday); varFullsunday = getfulldate (+nowdate + (7-nowday) *timestampofday); //Early month, month end varFullstartofmonth = Getfulldate (clonenowdate.setdate (1) ); varFullendofmonth =getfulldate (Clonenowdate.setdate (endOfMonth)); return{fulltoday:fulltoday, Fullyesterday:fullyesterday, Fullmonday:fullmonday, Fullsunday: Fullsunday, Fullstartofmonth:fullstartofmonth, fullendofmonth:fullendofmonth};} ());
Second, the package is a module, can be used for webpack tool packaging
varNowdate =NewDate ();varClonenowdate =NewDate ();varFullyear =nowdate.getfullyear ();varmonth = Nowdate.getmonth () + 1;//the GetMonth method returns 0-11, representing January-DecembervarDate =nowdate.getdate ();varEndOfMonth =NewDate (fullyear, month, 0). GetDate ();//get the last day of the month//formatted Date (2016-02-14)functiongetfulldate (targetdate) {vard, Y, M, D; if(targetdate) {D=NewDate (targetdate); Y=d.getfullyear (); M= D.getmonth () + 1; D=d.getdate (); } Else{y=fullyear; M=month; D=date; } m= m > 9? M: ' 0 ' +m; D= d > 9? D: ' 0 ' +D; returnY + '-' + M + '-' +D;}//Timestamp of the day (in milliseconds)varTimestampofday = 1000*60*60*24;//Today, yesterdayvarFulltoday =getfulldate ();varFullyesterday = Getfulldate (Nowdate-timestampofday);varNowday = Nowdate.getday ();//The GetDay method returns 0 for SundayNowday = Nowday = = = 0? 7: Nowday;//this Monday, the end of the week (Sunday)//Note: Under Safari (Nowdate +-0) is not converted to a timestamp, where the operator + is preceded by the nowdate, and the timestamp operation is manually convertedvarFullmonday = Getfulldate (+nowdate-(nowDay-1) *timestampofday);varFullsunday = getfulldate (+nowdate + (7-nowday) *timestampofday);//Early month, month endvarFullstartofmonth = Getfulldate (clonenowdate.setdate (1) );varFullendofmonth =getfulldate (Clonenowdate.setdate (EndOfMonth)); Module.exports={fulltoday:fulltoday, Fullyesterday:fullyesterday, Fullmonday:fullmonday, Fullsunday:fullsunday, Fullstartofmonth:fullstartofmonth, fullendofmonth:fullendofmonth};
JavaScript Date collection (Today, yesterday, this Monday, weekend, early month, month end)