JavaScriptの日付タイプに関する共通操作の概要
** 3。 date.StringTodate:文字列を日付タイプ10に変換します。 *(7)日付。-デイズベット:2つの日付の日数11の差を計算します。 date.prototype.toarray:日付を配列に分割します。配列番号に従って、それぞれ年、月、時間、分、秒です。 *(11)date.prototype.datePart:日付データ情報を取得15。 *例:21。 *(1)アラート(date.isvalidate( '2008-02-29'、 'yyyymm-dd')); // true 22。 (1)yyyy-mm-dd(デフォルト形式)またはyyyy-mm-dd(2)yyyy/mm/ddまたはyyyy/mm/dd(3)mm-dd-yyyyまたはmm-dd-yyy(4)mm/dd/yyyyまたはmm/dd/yyyy 25。 formatstr)27。{28。if(!datestr){29。turnfalse; 30。} 31。if(!formattr){32。formattr= "yyyymm-dd"; //デフォルト形式:yyyymm-dd 33。} 34。 36。} else {37 r1=/^((((((((((((((((((((((((((((((((((((((((((((((((((([02468] [048]))) ((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)|(30)|(02/ - ([0-2] [0-2])|(30)|(02] |(02] |(02] |」 - ([0-2] [0-2])|(30))|(02/ - ([0-2] [0-2])|(30))|(02/ - ([0-2] [0-2])|(30))|(02/ - ([0-2])|(30))|(30))|(02/ - ] ]))))|(/d {2}(([02468] [1235679])|([13579] [01345789]))/ - (((0 [13578]))|((1 [02]))/ - (([0-2] [0-9])|(3 [01]))))))))))|(11))/ - (([0-2] [0-9])|(30))))))))))))))|(([0-1] [0-9]))|((2 [0-8])))))) 39。return r1.test(datestr); r2=/^((((((((((((((((((((((((((((((((((((((((((((((((((((([0246 8])))))))))))))))|(1 [02]))))))))))) ((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)|(30)|(02 //([0-2] [0-2])|(30)|(02] |(02] |(30-2])| //([0-2] [0-2])|(30))|(02 //([0-2] [0-2]))|(30))|(02 //([0-2])|(30))|(02)|(02] [0-2])|(30)|(02 //(02 //」 ]))))|(/d {2}(([02468] [1235679])|([13579] [01345789]))//(((0 [13578]))|((1 [02]))//(((0-2])[((0-2]))[ 0-9] |(3 [01]))))))))))))|(11))//(([0-2] [0-9])|(30))))))))))))))))))))|(([0-1] [0-8]))|((2 [0-8])))) 42。return r2.test(datestr); r3 =/^(((((((((((((0 13578]))))|(1 [02])))))/ - ((([0-2] [0-9])|(3 [01]))))|((0 [469]))|(11))))))))))))))))|(((((0-2]] [0-9])|(0-2/ - 」 -9])))))(((((((([02468] [048]])|」)|([13579] [26])(00))|((/d {2}(([02468] [48])|([13579] [26])(00))| ]))))|((((0 [13578]))|(1 [02])))))))))))))|(3 [01]))))))))))|((11))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) |(30))))|(02/ - (([0-1] [0-9])|(2 [0-8])))/ - /d {2}(([02468] [1235679]))|([13579] [01345789]))$/; 45。return r3.test(datestr); r4 =/^(((((((((((((0 13578]]))))|(1 [02]))))) ))))(((((([02468] [048]))|([13579] [26])(00))|(/d {2}(([02468] [48])|([13579] [26])(00))|(/d {2}([02468])| ]))))|((((0 [13578]))|(1 [02]))))))))))))|(3 [01]))))))))))|(11)) |(30)))|(02 //(([0-1] [0-9])|(2 [0-8]))))))))))))))) 48。r4.test(dateStr);アラート(date.isvalitime('23:59:59 '、' hh:mm:ss ')); // true 62。 *(2)alert(date.isvalitime('24 -68-89'、 'hh:mm:ss')); (1)HH:MM:SS(デフォルト形式)(2)HH-MM-SS(3)HH/MM/SS 65 「HH:MM:SS "; //デフォルト形式:HH:MM:SS 73。}74。IF(Timestr.Length!= formatstr.length){75。If(formatstr ==" hh:mm:ss "){78。var r1 =/^([0-1] [0-9])|(2 [0-3])/:( [0-9])/:([0-9] [0-9])$/ r2 =/^([0-1] [0-9])|(2 [0-3])/ - ([0-5] [0-5] [0-9])$/ - return r2.test(timestr); R3 =/^([0-9])|(2 [0-3])///([0-5] [0-9] $/ false;}93。95./**96。 datetimereg =/^(((((((((((((((((((())))))) (((((((((((((((((((((((((((((([048]])))))))))))))|(((((02469]))|((11))|(((11)))/ - ((((((((((((((((((((()))))))))))))))))))))を得るのです。 (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((())))))」)」」」」」でたらないないないないないないないないないらできるにだできるできるできるならできるできるできるできるできるできるできるiIら光で(((((((((((((((((())))) (((1(1((1((1(1))))((1((1(1((1(1)))) ((1(1(1(1(1(1)))((1(1(1(1(1(1)))) 1((1(1(1(1(1(1(1)))) ((1(1(1(1(1(1)))((1(1(1(1(1(1)))) 8] [1235679])|([13579] [01345789])))))))))|(1 [02])))))))))|(3 [01]))))))))|((0 [469])|(11) )/ - (([0-2] [0-9])|(30)))|(02/ - (([0-1] [0-9])|(2 [0-8])))))))))))))))/:([0-5] [0-9])))))))))))))))) 102。DateTimereg.test(DateTimestr); (this.getyear()%4 == 0 &&((this.getyear()%100!= 0)||(this.getyear()%400 == 0));合意:119。 *(1)yyyy/yyy/yy/yyは120年を表します。 126。(8)III Milliseconds 127。 ['day'、 'two'、 'three'、 'five'、 'six']; 100).toString(): '0' +(this.getyear()%100); str.Replace(/m/g、(parseint(this.getmonth()) +1); this.getDate()); str.Replace(/h|h/g、gethours()); 152。Str.Replace(/Ss|ss/this.getSeconds()> 9?toString(): '0' + this.getSeconds()); this.getmilliseconds <10? '00'+this.getMilliseConds :( this.getMilliseConds+this.getMilliseConds():this.getMilliseConds())必須、日付文字列、日付タイプに解析できない場合、NULL 164を返します。 *形式:165。 *(1)yyyy/mm/dd:ieおよびff一般166。 169で解析されます。 */ 170.date.stringtodate(datestr)171。 if(date.isvalidate(dateStr、 "yyyy/mm/dd")|| date.isvalidate( "mm/dd/yyyy")){177。newdate(date.parse(datestr)); if(dateStr、 "mm-dd-yyy"){181。date.parse(datestr); date.isvalidate(yyyy-mm-dd "){188。189。 2つの日付間の日数の違いを計算します。202。 *日付:必須、データタイプ203のインスタンスでなければなりません。 return 0。選択された数字であり、正の数値は期間の追加であり、負の数は日付を差し引いています218。 D/D日224。(5)H/H時間225。(6)M分226。 *(7)S/S 227。 } 234。if(!field){235。field= "d";} switch(field){238。Case 'y':(this.gettryear()+num)、this.getmonth()、this.getdate()、this.gethours()、this.gets(); 'Q':241。Case 'Q':new Date(this.getTheer()、(this.getMonth()+num*3)、this.gethours()、this.getsuntes()、this.getseconds(); case 'm':return new.getmon( this.gethours()、this.getseconds(); break; 248。 'H':date.parse +(3600000 * num); case 'm':date.parse(this) +(60000 * num);これ。}256。258。 (2)Mか月265。(3)週266。(4)D/D日267。(5)H/H時間268日付)== {275。return 0; (dtend.getmonth()+1)+((dtend.get.fulyear() - dtstart.get.getmonth()+1); break(dtend.getmonth()+1); (dtend.getmonth()+1)+((dtend.get.fulyear() - dtstart.gettryear() * 12) - (dtstart.getmonth()+1); parseint(dtend -dtstart) / 86400000; case 'h':case 'h':(dtend -dtstart) / 3600000); 'M':parseint(dtend -dtstart) / 60000); case 's':292。Case 'M':Parseint((dtend -dtstart) / 60000);ケース ':292。 dtstart) / break; case 's':292。配列:年、1日、時間、202年、303.date.prototy.toarray()304。 309。myarray [310] = this.getsury();このパラメーターが使用できない場合、デフォルトはd 319です。 *(1)y/y Year 320。 *(2)m month 321。 *(3)w/w週322。 328. {329。if(!field){330 (this.getmonth()+1); case 'w':case 'w':case 'd' this.getminutes();JavaScriptの日付タイプに関する一般的な操作の上記の要約は、私があなたと共有するすべてのコンテンツです。参照を提供できることを願っています。wulin.comをもっとサポートできることを願っています。