JavaScript date format (JS day format) __js

Source: Internet
Author: User



[JavaScript]  View Plain copy//  the extension to date, converting  Date  to the string   //  month (M), day (d), hour (h), minute (m), SEC (s), quarter (q)   can use  1-2  placeholders,   //  years (y) can use  1-4  placeholders, milliseconds (s) can only be used with   1  placeholder (is a  1-3  digit)    //  example:   //  (New date ()). Format ("Yyyy-mm-dd hh:mm:ss. S ")  ==> 2006-07-02 08:09:04.423   //  (New date ()). Format ("YYYY-M-D H:M:S.S")       ==> 2006-7-2 8:9:4.18     date.prototype.format = function (FMT)     { //author: meizz       var o = {         "m+"  :  This.getmonth () +1,                  //month          "d+"  : this.getdate (),                    // Day          "h+"  : this.gethours (),                    //hours          "m+"  : this.getminutes (),                  //         "s+" &NBSP:  this.getseconds (),                  //sec          "q+"  : math.floor ((This.getmonth () +3) /3),  //quarterly          "S"   : this.getmilliseconds ()               //milliseconds       };     &nbsP; 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])  :  (("+ o[k]). substr ((" "" + o[k]) (length));      return fmt ;   }  

Call Method:

[JavaScript] view plaincopy var time1 = new Date (). Format ("Yyyy-mm-dd HH:mm:ss");    var time2 = new Date (). Format ("Yyyy-mm-dd");
Method Two:[JavaScript]  View Plain copy <mce:script language= "javascript"  type= "Text/javascript" ><!--            /**         *   Extension of date to convert  Date  to string         *  month (M), day (d) of the specified format , 12 hours (h), 24 hours (h), minutes (m), SEC (s), Week (E), quarter (q)   can be used  1-2  placeholder          *  year (y) can be used  1-4  placeholders, milliseconds (s) can only be used  1  placeholder (is the number of  1-3  digits)           * eg:         *  (New date ( ). Pattern ("yyyy-mm-dd hh:mm:ss.") S ")  ==> 2006-07-02 08:09:04.423         *  (new  date ()). Pattern ("Yyyy-mm-dd e hh:mm:ss")  ==> 2009-03-10  two  20:09:04        

Related Article

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.