Time formatter function Date.prototype.format = function (format) { var o = { "m+": This.getmonth () + 1,//month "d+": THIS.G Etdate (),//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 The if (/(y+)/.test (format)) 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;}
How to use: 1new Date (blog. addtime). Format (' Yyyy-mm-dd hh-mm-ss ');
//time format Function Date.prototype.format = function (format) {var o = { "m+": This.getmonth () + 1,//month "d+": This.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 (format)) format = Format.replace (RegExp . $, (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;} Presentation list data function Addtablerow (productionobj) {var fields = ["Get (' title ')", "Get (' content ')", "Createdat.format (' Yyyy-mm-dd hh:mm:ss ')" ];
Original address: http://www.cnblogs.com/henw/archive/2011/10/17/2215545.html
JS Time Format function