Tag:substr support Date regex exp Formatting log format div
function DateFormat (datestring,format) { if (!datestring) return ""; var time = new Date (Datestring.replace (/-/g, '/'). Replace (/t| Z/g, "). Trim ()); var o = { "m+": Time.getmonth () + 1,//month "d+": time.getdate (),//day "H +": time.gethours (),//hour "m+": Time . getminutes (),//Sub " s+": Time.getseconds (),//sec "q+": Math.floor ((Time.getmonth () + 3)/3),//quarterly "s": Time.getmilliseconds ()//msec }; if (/(y+)/.test (format)), format = Format.replace (regexp.$1, (time.getfullyear () + ""). substr (4-regexp.$1.length)); C12/>for (var k in O) if (New RegExp ("(" + K + ")"). Test (format)) format = Format.replace (regexp.$1, (regexp.$1.lengt h = = 1)? (O[k]): (("XX" + o[k]). substr (("" + O[k]).)); return format; }
Compatible with IE8 's JS formatted date method, to resolve IE8 does not support the issue of date ()