This article introduces the date formatting algorithm of the next JS. The specific implementation is as follows. If you are interested, refer to it and hope to help you.
The Code is 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? ("000" + o [k]). substr ("" + o [k]). length): ("00" + o [k]). substr ("" + o [k]). length ));
}
}
Return format;
}