/*File Created: April*///date plus days to get new date//Datetemp need to participate in the calculation of the date, days to add the day, return the new date, date format: Yyyy-mm-ddfunctiongetnewday (Datetemp, days) {varDatetemp = Datetemp.split ("-"); varNdate =NewDate (datetemp[1] + '-' + datetemp[2] + '-' + datetemp[0]);//Convert to MM-DD-YYYY format varMillseconds = Math.Abs (ndate) + (days * 24 * 60 * 60 * 1000); varRdate =NewDate (millseconds); varYear =rdate.getfullyear (); varmonth = Rdate.getmonth () + 1; if(Month <) month = "0" +month; varDate =rdate.getdate (); if(Date <) date = "0" +date; return(Year + "-" + month + "-" +date);}functiongetDate (strdate) {varDate = eval (' New Date ' (' + strdate.replace ') (/\d+ (? =-[^-]+$)/, function(a) {returnparseint (A, 10)-1; }). Match (/\d+/g) + ') '); returndate;}//override the ToString method to convert the time to y-m-d h:i:s formatDate.prototype.toString =function () { return This. getFullYear () + "-" + ( This. GetMonth () + 1) + "-" + This. GetDate () + "" + This. GetHours () + ":" + This. getminutes () + ":" + This. getseconds ();}//format Time StringDate.prototype.toFormatString =function(format) {if(Format = = "") { return This. toString (); } varstr = "; STR= Format.replace (/y|y/, This. getFullYear ()). Replace (/m|m/, This. GetMonth () + 1). Replace (/d|d/, This. GetDate ()). Replace (/h|h/, This. GetHours ()). Replace (/i|i/, This. getminutes ()). Replace (/s|s/, This. getseconds ()); returnstr;}//number of years to add at the current timeDate.prototype.addYear =function(years) {varCyear = This. getFullYear (); Cyear+=years; This. Setyear (Cyear); return This;}//add a number of days to the current timeDate.prototype.addDay =function(days) {varcd = This. GetDate (); CD+=Days ; This. SetDate (CD); return This;}//add a number of months at the current timeDate.prototype.addMonth =function(months) {varCM = This. GetMonth (); CM+=months; This. setmonth (CM); return This;}//Convert PHP time format (y-m-d h:i:s) to JS Date Objectfunctionphpdatetojsdate (phpdate) {if(Phpdate = = "") { return NewDate (); } return NewDate (Date.parse (Phpdate.replace (/-/g, "/")));}
JS Date extension method