JavaScript Date collection (Today, yesterday, this Monday, weekend, early month, month end)

Source: Internet
Author: User
Tags getdate


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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.