JavaScript format time Date function code Script Home Fix Edition _ time date

Source: Internet
Author: User
<textarea id="runcode57792"><script> Date.prototype.format = function (format) {var o = {"m+": This.getmonth () +1,//month "d+": Thi S.getdate (),//day "h+": this.gethours (),//hour "m+": This.getminutes (),//minute "s+": This.getseconds (),//second "q+": Math.floor (This.getmonth () +3)/3),//quarter "S": This.getmilliseconds ()//millisecond} if (/(y+)/.test (forma T)) Format=format.replace (Regexp.$1, (this.getfullyear () + ""). substr (4-regexp.$1.length)); For (var k in O) if (new RegExp ("+ K +")). Test (format) format = Format.replace (regexp.$1, regexp.$1.length==1? O[k]: ("+ o[k]"). substr (("" + o[k]). length); return format; }//called method var t=new Date (); document.write ("Before formatting:" +t+ "<br>"); T=new Date (). Format ("Yyyy-mm-dd hh:mm:ss"); document.write ("formatted:" +t); </script></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

JavaScript Format Date Time Function _ Time Date _ Cloud Habitat Community
Http://www.jb51.net/article/14753.htm

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.