1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30-31 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 The 96 97 98 99 100 101 102 103 104 105 106 107 108 109 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140-1 41 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170-171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201-2 02 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231-232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
Judge Leap Year//---------------------------------------------------Date.prototype.isLeapYear = function () {return (0== This.getyear ()%4&& (This.getyear ()%100!=0) | | (This.getyear ()%400==0)); //---------------------------------------------------//Date format//Format YYYY/YYYY/YY/YY = year//mm/m month//w/w Week// DD/DD/D/D Date//hh/hh/h/h time//mm/m minute//ss/ss/s/s seconds//---------------------------------------------------Date.prototy Pe. Format = function (formatstr) {var str = formatstr; var Week = [' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ']; Str=str.replace (/yyyy | Yyyy/,this.getfullyear ()); Str=str.replace (/yy| yy/, (this.getyear ()%) >9? (This.getyear ()%). ToString (): ' 0 ' + (this.getyear ()% 100)); Str=str.replace (/mm/,this.getmonth () >9?this.getmonth (). toString (): ' 0 ' + this.getmonth ()); Str=str.replace (/m/g,this.getmonth ()); Str=str.replace (/w| W/g,week[this.getday ()]); Str=str.replace (/dd| Dd/,this.getdate () >9?this.getdate (). toString (): ' 0 ' + this.getdate ()); STr=str.replace (/d| D/g,this.getdate ()); Str=str.replace (/hh| Hh/,this.gethours () >9?this.gethours (). toString (): ' 0 ' + this.gethours ()); Str=str.replace (/h| H/g,this.gethours ()); Str=str.replace (/mm/,this.getminutes () >9?this.getminutes (). toString (): ' 0 ' + this.getminutes ()); Str=str.replace (/m/g,this.getminutes ()); Str=str.replace (/ss| Ss/,this.getseconds () >9?this.getseconds (). toString (): ' 0 ' + this.getseconds ()); Str=str.replace (/s| S/g,this.getseconds ()); return str; } //+---------------------------------------------------//| A two-time number of days difference date format is YYYY-MM-DD//+---------------------------------------------------function Daysbetween (Dateone, Datetwo) {var onemonth = dateone.substring (5,dateone.lastindexof ('-')); var oneday = dateone.substring (DateOne.length, Dateone.lastindexof ('-') +1); var oneyear = dateone.substring (0,dateone.indexof ('-')); var twomonth = datetwo.substring (5,datetwo.lastindexof ('-')); var twoday = datetwo.substring (datetwo.length,datEtwo.lastindexof ('-') +1); var twoyear = datetwo.substring (0,datetwo.indexof ('-')); var cha= (Date.parse (onemonth+ '/' +oneday+ '/' +oneyear ')-date.parse (twomonth+ '/' +twoday+ '/' +twoyear '))/ 86400000); Return Math.Abs (CHA); } //+---------------------------------------------------//| Date Calculation//+---------------------------------------------------Date.prototype.DateAdd = function (strinterval, number) { var dttmp = this; Switch (strinterval) {case ' s ': return new Date (Date.parse (dttmp) + (1000 * number)), Case ' n ': return new Date (Date.pars E (dttmp) + (60000 * number)); Case ' H ': return new Date (Date.parse (dttmp) + (3600000 * number)); Case ' d ': return new Date (Date.parse (dttmp) + (86400000 * number)); Case ' W ': Return new Date (Date.parse (dttmp) + ((86400000 * 7) * number)); Case ' Q ': return new Date (Dttmp.getfullyear (), (Dttmp.getmonth ()) + number*3, Dttmp.getdate (), dttmp.gethours (), Dttmp.getminutes (), dttmp.getseconds ()); Case ' m ': return new Date (Dttmp.getfullyear (), Dttmp.getMonth ()) + number, dttmp.getdate (), dttmp.gethours (), Dttmp.getminutes (), dttmp.getseconds ()); Case ' Y ': Return new Date ((dttmp.getfullyear () + number), Dttmp.getmonth (), Dttmp.getdate (), dttmp.gethours (), Dttmp.getminutes (), dttmp.getseconds ()); }} //+---------------------------------------------------//| Compare Date Difference dtend format is a date type or a valid date format string//+---------------------------------------------------Date.prototype.DateDiff = function (Strinterval, dtend) {var dtstart = this; if (typeof dtend = ' string ')//if the string is converted to date type {dtend = Stringtodate (DtE nd); Switch (strinterval) {case ' s ': Return parseint (Dtend-dtstart)/1000), Case ' n ': Return parseint ((Dtend-dtstart) /60000); Case ' H ': Return parseint ((dtend-dtstart)/3600000); Case ' d ': Return parseint ((dtend-dtstart)/86400000); Case ' W ': Return parseint (Dtend-dtstart)/(86400000 * 7)); Case ' m ': Return (Dtend.getmonth () +1) + ((Dtend.getfullyear ()-dtstart.getfullyear ()) *12)-(Dtstart.getmonth () +1); Case ' Y ': return DTEND.GEtfullyear ()-dtstart.getfullyear (); }} //+---------------------------------------------------//| The date output string that overloads the system's ToString method//+---------------------------------------------------Date.prototype.toString = function (Showweek) {var mydate= this; var str = mydate.tolocaledatestring (); if (Showweek) {var Week = [' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' Six ']; STR + = ' Week ' + week[mydate.getday ()]; return str; } //+---------------------------------------------------//| Date legality Verification//| Format is: YYYY-MM-DD or yyyy/mm/dd//+---------------------------------------------------function isvaliddate (datestr) { var sdate=datestr.replace (/(^s+|s+$)/g, ""); Go to both sides of the space; if (sdate== ') return true; If the format satisfies the yyyy-(/) mm-(/) DD or yyyy-(/) m (/) DD or yyyy-(/) m (/) d or yyyy-(/) mm-(/) d is replaced with the '//database, the legal date can be: Yyyy-mm/dd (2003-3/ 21), the database is automatically converted to the YYYY-MM-DD format var s = sdate.replace (/[d]{4,4}[-/]{1}[d]{1,2}[-/]{1}[d]{1,2}/g, ""); if (s== ')//description format satisfies YYYY-MM-DD or YYYY-M-DD or yyyy-m-d or yyyy-mm-d {var t=new Date (Sdate.replace, '/')); var ar= Sdate.split (/[-/:]/); if (Ar[0]!= t.getyear () | | ar[1]!= t.getmonth () +1 | | ar[2]!= t.getdate ()) {//alert (' Wrong date format! The format is: Yyyy-mm-dd or YYYY/MM/DD. Notice leap year. '); return false; } else {//alert (' Wrong date format! The format is: Yyyy-mm-dd or YYYY/MM/DD. Notice leap year. '); return false; return true; } //+---------------------------------------------------//| Date Time Check//| Format is: yyyy-mm-dd HH:MM:SS//+---------------------------------------------------function checkdatetime (str) {var reg = /^ (d+)-(d{1,2})-(D{1,2}) (d{1,2}):(d{1,2}):(d{1,2}) $/; var r = Str.match (reg); if (r==null) return false; R[2]=r[2]-1; var d= new Date (R[1],r[2],r[3],r[4],r[5],r[6]); if (D.getfullyear ()!=r[1]) return false; if (D.getmonth ()!=r[2]) return false; if (D.getdate ()!=r[3]) return false; if (D.gethours ()!=r[4]) return false; if (D.getminutes ()!=r[5]) return false; if (D.getseconds ()!=r[6]) return false; return true; } //+---------------------------------------------------//| Dividing dates into groups//+---------------------------------------------------Date.prototype.toArray = function () {var mydate = this; var myarray = Array (); myarray[0] = Mydate.getfullyear (); myarray [1] = Mydate.getmonth (); MYARRAY[2] = Mydate.getdate (); MYARRAY[3] = mydate.gethours (); MYARRAY[4] = Mydate.getminutes (); MYARRAY[5] = Mydate.getseconds (); return myarray; } //+---------------------------------------------------//| Get Date data Information//| The parameter interval represents the data type//| Y year M month d days W week WW Week h when N minute s sec//+---------------------------------------------------Date.prototype.DatePart = function (inter val) {var mydate = this; var partstr= '; var Week = [' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ']; switch (interval) {case ' Y ':p artstr = Mydate.getfullyear (); Case ' m ':p artstr = Mydate.getmonth () +1;break; Case ' d ':p artstr = Mydate.getdate (); Case ' W ':p artstr = Week[mydate.getday ()];break; Case ' ww ':p artstr = Mydate.weeknumofyear (); Case ' h ':p artstr = mydate.gethours (); Case ' n ':p artstr = Mydate.getminutes (); Case ' s ':p artstr = Mydate.getseconds ();; return partstr; } //+---------------------------------------------------//| Gets the maximum number of days in the month of the current date//+---------------------------------------------------Date.prototype.MaxDayOfDate = function () {var MyDate = this; var ary = Mydate.toarray (); var date1 = (new Date (ary[0],ary[1]+1,1)); var date2 = date1.dateadd (1, ' m ', 1); var result = DateDiff (date1. Format (' Yyyy-mm-dd '), Date2. Format (' yyyy-mm-dd ')); return result; } //+---------------------------------------------------//| Get the current date the week is the week ordinal of the year//+---------------------------------------------------Date.prototype.WeekNumOfYear = function () {var mydate = this; var ary = Mydate.toarray (), var year = ary[0], var month = ary[1]+1; var day = ary[2]; document.write (' < script language=vbscript> n '); document.write (' mydate = Datue (' +month+ '-' +day+ '-' +year+ ') n '); document.write (' result = DatePart (' ww ', mydate) n '); document.write (' n '); return result; } //+---------------------------------------------------//| string is converted to date type//| Format mm/dd/yyyy mm-dd-yyyy yyyy/mm/dd yyyy-mm-dd//+---------------------------------------------------function Stringtodate (datestr) { var converted = Date.parse (DATESTR); var mydate = new Date (converted); if (isNaN (mydate)) { var Delimcahar = datestr.indexof ('/')!=-1? ' /':'-'; var arys= datestr.split ('-'); MyDate = new Date (Arys[0],--arys[1],arys[2]); return mydate; } |