This article for you to introduce the next JS date format algorithm, the specific implementation of the following, interested friends can refer to the hope that you have some help to
copy code code as follows:
function DateFormat (date, format) {
var o = {
"m+": Date.getmonth () + 1,//month
"D+": Date.getdate (),//day
"h+": date.gethours (),//hour
"m+": Date.getminutes (),//minute
"S+": Date.getseconds (),//second
"q+": Math.floor (Date.getmonth () + 3)/3),//quarter
"S": Date.getmilliseconds ()//millisecond
};
Replace YYYY with a specific year
if (/(y+)/.test (format)) {
Format = Format.replace (regexp.$1, (date.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]). substr ((" "+ o[k]). Length): (" + o[k] "). substr ((" "" + o[k]). length);
}
}
return format;
}