JS Date Parse

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.