JavaScript의 날짜 유형에 대한 공통 작업 요약
/** 3. * DATE.ISVALIDATE : DATE LEGALITY 5. (2) DATE.ISVALITIME : 시간 합법성 검증 6. DATE.STRINGTODATE : 문자열을 날짜로 변환하십시오. * (7) 날짜. date.prototype.toArray : 날짜를 배열로 나눕니다. 배열 번호에 따르면, 그것은 각각 연도, 월, 일, 시간, 분 및 두 번째입니다. * (11) date.prototype.DatePart : 날짜 데이터 정보 가져 오기 15. */ 16. 17. 18./** 19. * 예 : 21. * (1) Alert (Date.isValidate ( '2008-02-29', 'yyyy-mm-dd')); // true 22. (1) yyyy-mm-dd (기본 형식) 또는 yyyy-mm-dd (2) yyyy/mm/dd 또는 yyyy/mm/dd (3) mm-dd-yyyy 또는 mm-dd-yyyy (4) mm/dd/yyyyy 또는 mm/dd/yyyyy 25. 함수 (datest, formatstr) 27. {28. if (! datest) {29. 거짓; 30.} 31. if (! formatstr) {32. formatstr = "yyyy-mm-dd"; // 기본 형식 : yyyy-mm-dd 33.} 34. if (dateStr.Length! = formatstr.length) {35. 거짓; 36.} else {37. if (formatstr == "yyyy-mm-dd"|| formatstr == "yyyy-mm-dd") {38. var R1 =/^((((((() [048])))))/-(((((0 [13578]) | (1 [02]))/-((((((0 [0 [13578])) | (1 [02]))/-((() ((0-2] [0-9]) | (3 [01]))) | ((((0 [469])) | (11))/-((([0-2] [0-9])) | (30)) | ( 02/-([0-2] [0-2]) | (30))) | (02/-([0-2] [0-2]) | (3 [01])) | (((0 [469]) | (1 1))/-(((((0-2] [0-9]) | (30))) | (02/-([0-2] [0-2]) | (30)) | (02/-([0-2] [0-2]) | (30)) | (02/-([0-2] [0-2]) | (30)) | (02] | (0-2])) -([0-2] [0-2]) | (30)) | (02/-([0-2] [0-2]) | (30)) | (02/-([0-2] [0-2])) | (30)) | (02/-([0-2] [0-2] [0-2] [0-2]) | (30)) | (02/-([0-2] [0-2]) | ! [0-9] | (3 [01])) | ((0 [469]) | (11))/-(([0-2] [0-9]) | (30)) | (02/-([0-1] [0-9]) | (2 [0-8]))))) $/; 39. R1.test (DateSt)를 반환합니다 R2 =/^((((((() 8] [048]))))) // ((((0 [13578]) | (1 [02])) // (((((0-2] [0-9])) | (3 [01])) | ( ((0 [469]) | (11)) // ((((([0-2] [0-9])) | (30))) | (02 // ([0-2] [0-2]) | (30))) | (02 // ([0-2] [0-2]) | (3 [01])) | (((0 [469]) | (11)) // ((((((0-2] [0-9])) | (3 0)) | (02 // ([0-2] [0-2]) | (30)) | (02 // ([0-2] [0-2]) | (30)) | (02 // ([0-2] [0-2]) | (30)) | (02 // ([0-2] [0-2]) | (30)) | (02] | (0-2]) | (0-2]) // ([0-2] [0-2]) | (30)) | (02 // ([0-2] [0-2]) | (30)) | (02 // ([0-2] [0-2]) | (30)) | (02 // ([0-2] [0-2] [0-2] [0-2] [0-2] [0-2] [0-2]) | (30)) | ] [0-9])))) | (/d {2} (([[02468] [1235679]) | ([13579] [01345789]))) // (((0 [13578]) | (1 [02])) // ((0-2] 0-9]) | (3 [01])) | ((0 [469]) | (11)) // (([0-2] [0-9]) | (30))) | (02 // ([0-1] [0-9]) | (2 [0-8]))))) $/; 42. RETURN R2.TEST (DateSt); 43 R3 =/^((((((((0 [13578]))) | ((0 [02]))/-((([0-2] [0-9])) | (([0-2] [0-9])) | (([0-2] [0-9])) | (([0-2] [0-9])) | (([0-2] [0-9])) | (([0-2] [0-9])) | (([0-2] [0-9])) | (([0-2] [0-9]) | (([0-2] [0-9])) | ((([0-2] [0-9])) | ((0-9]) | ((((0-2] [469]))))))))))))) -9]))))))/-((((([02468] [048])) | ([13579] [26]) (00)) | (/d {2} ([[02468] [48]) | ! | (30)))) | (02/-(([0-1] [0-9]) | (2 [0-8])))))/-/d} (([[02468] [1235679]) | ([13579] [01345789]))) $/; 45. R3.test (DateSt); 46 R4 =/^(((((((0 [13578])) | ((0 [02])) // (([0-2] [0-9]) | (3 [01])) | ((0 [469]) | (11)) // ((([0-2] [0-9]) | (30)) | (02 // [0-2] ))) // ((((([02468] [048]) | ([13579] [26])) (00)) | (/d {2 {[[02468] [48]) | ([13579] [26]))) | (/d {2} ([02468]) | [48]) ] [26]))))) | (((0 [13578]) | (1 [02])) // (([0-2] [0-9]) | (3 [01]))) | ((0 [469]) | (11)) // (([0-2] [0-9]) | (30)))) | (02 // ([0-1] [0-9]) | (2 [0-8])))) // d {2} (([[02468] [1235679]) | ([13579] [01345789]))) $/; 48. reture (49.} else {51). ALERT (DATE.ISVALITIME ('23 : 59 : 59 ','HH : MM : SS '); // true 62. * (2) Alert (date.isvalitime ('24-68-89', 'HH : MM : SS')); // False 63)); (1) HH : MM : SS (기본 형식) (2) HH-MM-SS (3) HH/MM/SS 65. */66.date.isvalitime = function (timest, formatstr) 67. {68 "HH : MM : SS"; // 기본 형식 : HH : MM : SS 73.} 74. if (timest.length.length) {75. return false {77. if (formatstr == "hh : mm : ss") {78 r1 =/^([0-1] [0-9]) | (2 [0-3]))/: ([0-5] [0-9]) $/79 R2 =/^([0-1] [0-9]) | (2 [0-3]))/-([0-5] [0-9]) $/; R3 = ([0-3]) | (2 [0-3]) // ([0-5] [0-9]) $/; False; 92.} 93. 94./** 96. dateTimereg =/^((((((() ((((((. (((((((() ((((((() ((1 ((1 ((1) ((1 (1 (1 (1) (1 (1 (1 (1 (1 (1) ((1 (1 (1 (1 (1) 8] [1235679]) | ([13579] [01345789])))/-((((0 [13578]) | (1 [02])))))))))))) ))/-([0-2] [0-9]) | (30))) | (02/-([0-1]))))))))))))))))))))))/: ([0-5] [0-9])))/: ([0-5] [0-9]))? $/ 102. DateTimereg.test (dateTimest) 103.} 104. 105. 106 (this.getyear ()%4 == 0 && (this.getyear ()%100! = 0) || (this.getYear ()%400 == 0)); 합의 : 119. * (1) YYYY/YYY/YY/YY는 120 년을 나타냅니다. * (2) mm/m Month 121. 126. (8) iii 밀리 초 127. */128.date.prototype.format = function (formatstr) 129. {130. var str = formatstr; if (! formatstr) {132. [ 'Day', 'One', 'Two', 'Three', 'Four', 'Five', 'Six']; str.replace (/yyyyyoyyyy/, this.getlyear ()); 100) .toString () : '0' + (this.getyear () % 100)); str = str.replace (this.getmonth (). str.replace (/m/g, parseint (this.getmonth ()) +1); str.replace (/w | w/g, this.getday ()); getDate (); 145. str.replace (/d|d/ghis.getDate ()); str.replace (/h|h/g, this.gethours ()); 149. str.replace (/ss|ss/, this.getSeconds ()> 9? getSeconds () : '0' + this.getSeconds ()); this.getmilliseconds () <10? '00'+this.getmilliseconds () :( this.getmilliseconds () <getmilliseconds () : this.getmilliseconds ()); 날짜 문자열, 날짜 유형으로 구문 분석 할 수없는 경우, 반환 NULL 164. * 형식 : 165. * (1) YYYY/MM/DD : IE 및 FF General 166. * (2) MM/DD/YYYY : IE 및 FF는 일반적입니다. 169. */ 170.StringTodate = function (datest) 171에 구문 분석. if (date.isvalidate (datest, "yyyy/mm/dd") || date.isvalidate (datest, "mm/dd/yyyy")) {177. return new date (date.parse (datest)) {179. if (date.isvalidate (datest), "mm-dd-yyyy") {181. else.183. if (Date.isValidate, "yyyy-mm-dd") {188. else {190. 두 날짜 사이의 일 수의 차이를 계산합니다. 202. else {210. Return Math.abs (Math.floor ((dateone.gettime ())/1000/60/60/24) 213. 214 ./** 216. 숫자 및 양수는 기간 첨가이며, 음수 숫자는 날짜 뺄셈입니다. * 필드 : 옵션, 어떤 필드가 추가되거나 빼고 있는지 식별하면,이 매개 변수를 사용할 수없는 경우 필드는 d 219입니다. * * 다음 형식은 220. (1) y/y 221. 224. (5) H/H 시간 225. * (6) M 분 226. if (! field) {235. "D"; 241. 'Q': 새 날짜를 반환합니다 (this.getLyear (), (this.getMonth ()+num*3), this.getHours (), this.getMinutes (), getSeconds ()); break ': return new Date (this.getlyThear (), this () this.gethours (), this.getseconds ()); break; 248 'h': 날짜 255.} 256. 257. 258./** 259. (2) 265. (3) W/W 주 266 DATE) {275. 276. {277. 278. 279.} 280. 'y': 282 (dtend.getmonth ()+1)+((dtend.getlyear () -dtstart.getlyear ()) - (dtstart.getmonth ()+1); Break; (dtend.getmonth ()+1)+((dtend.getlyear () - dtstart.getlyear ()) - (dtstart.getmonth ()+1); break; parseint (dtend -dtstart) / 86400000 'M': Parseint ((dtend -dtstart) / 60000); break; 291. case 's': case 'm': parseint ((dtend -dtstart) / 60000); DTSTART); BREAK; 292. 292. 배열에 따르면 : 연도, 월, 날, 시간, 분, 두 번째. MyArray [3]. 310. 이 매개 변수를 사용할 수없는 경우, 기본값은 d 319입니다. * (1) y/y 년 320. * (2) m Month 321. * (3) W/W 주 322. (4) D/D Day 323. * (5) H/H 시간 324. 328. if (! field) {330. "D"; (get.+1); 337. 338 getminutes (); 344; getSeconds ();JavaScript의 날짜 유형에 대한 공통 작업에 대한 위의 요약은 내가 공유하는 모든 컨텐츠입니다. 나는 당신이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.