Tag:for apr not remove string efault his may oct
On the basis of previous improvements, the original code can not be run. You can use it first. Date.prototype.format = function (mask) {var d = this; var zeroize = function (value, length) {if (!length) length = 2; Value = String (value); for (var i = 0, zeros = '; i < (length-value.length); i++) {zeros + = ' 0 ';} return zeros + value; }; Return Mask.replace (/(?:d {1,4}| M{1,4}|yy (?: yy) | h{1,2}|h{1,2}|m{1,2}|s{1,2}| [llz]|tt|tt)/g, function ($) {switch ($) {case ' d ': return D.getdate (); case ' DD ': Return Zeroize (D.getdate ()); DDD ': return [' Sun ', ' Mon ', ' Tue ', ' Wed ', ' Thr ', ' Fri ', ' Sat '][d.getday ()]; Case ' dddd ': return [' Sunday ', ' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ', ' Saturday '][d.getday ()]; Case ' M ': Return D.getmonth () + 1; Case ' MM ': Return Zeroize (D.getmonth () + 1); Case ' MMM ': return [' Jan ', ' Feb ', ' Mar ', ' April ', ' may ', ' June ', ' Jul ', '][d.getmonth ', ' Sep ', ' Oct ', ' Nov ', ' Dec ' ()]; Case ' MMMM ': return [' January ', ' February ', ' March ', ' April ', ' may ', ' June ', ' July ', ' August ', ' September ', ' October ', ' No ' Vember ', ' December '][d.getmonth ()]; Case ' yy ': Return String (D.getfullyear ()). substr (2); Case ' yyyy ': return D.getfullyear (); Case ' H ': return d.gethours ()% 12 | | 12; Case ' hh ': Return Zeroize (d.gethours ()% 12 | | 12); Case ' H ': return d.gethours (); Case ' HH ': Return Zeroize (D.gethours ()); Case ' m ': return D.getminutes (); Case ' mm ': Return Zeroize (D.getminutes ()); Case ' s ': return D.getseconds (); Case ' SS ': Return Zeroize (D.getseconds ()); Case ' l ': Return Zeroize (D.getmilliseconds (), 3); Case ' L ': var m = d.getmilliseconds (); if (M > a) m = Math.Round (M/10); Return Zeroize (m); Case ' TT ': Return d.gethours () < 12? ' Am ': ' PM '; Case ' TT ': Return d.gethours () < 12? ' AM ': ' PM '; Case ' Z ': Return d.toutcstring (). Match (/[a-z]+$/); default://return quoted strings with the surrounding quotes removed return $0.substr (1, $0.length-2); } }); }; Call method: New Date (). Format ("YYYY-MM-DD HH:mm:ss L TT tt");
Java Script Date formatting (modified version)