<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