Because the Date conversion format in JS does not have a "-" delimiter, Date.parse generates Nan, so it can only be converted.
<script type= "Text/javascript" > function Changeweddingtime () { var dt= timeseparatorreplace (Marry_ Time.value); $ (wedding_date). html (dt. Format ("Yyyy/mm/dd")); var time = dt. Format ("hh:mm"); var hour = dt. Format ("H"); if (parseint (hour) >=) { $ (wedding_time). HTML (time + "+" PM "); } else { $ (wedding_time). HTML (Time + "" + "AM"); } } </script>
Methods of extending
Date.prototype.Format = function (FMT) {//author:meizz var o = {"m+": This.getmonth () + 1, Month "d+": this.getdate (),//day "H +": this.gethours (),//hour "m+": this.getminutes (),//min "s+": This.getseconds (),//sec "q+": M Ath.floor ((This.getmonth () + 3)/3),//Quarterly "S": Dataprivatepad (This.getmilliseconds (), 3)//MS }; if (/(y+)/.test (FMT)) FMT = Fmt.replace (regexp.$1, (this.getfullyear () + ""). substr (4-regexp.$1.length)); For (var k in O) if (New RegExp ("(" + K + ")"). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.length = = 1)? (O[k]): (("XX" + o[k]). substr (("" + O[k]).)); return FMT;} function Dataprivatepad (num, n) {return (Array (n). Join (0) + num). Slice (-N); Replace "-" with "/" function Timeseparatorreplace (str) {var regEx = new RegExp ("\\-", "GI"); str = STR.REPLACE (regEx, "/"); if (!isnan (Date.parse (str))) {return new Date (str); } else {return new Date ();//If it fails, just give the current time well}}
JS Date Parse