The FormatDate function is output in the time format in javascript. The time format is formatdate.
This example describes how to output the FormatDate function in time format in javascript. Share it with you for your reference. The details are as follows:
Javascript does not provide a function for inputting datetime content formats like fmt labels:
The following is my time output function, which is directly placed in the tag for calling. The Code is as follows:
Copy codeThe Code is as follows: Date. prototype. Format = function (fmt) {// author: meizz
If (this = "Invalid Date "){
Return "";
}
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 (fmt ))
Fmt = fmt. replace (RegExp. $1, (this. getFullYear () + "")
. Substr (4-RegExp. $1. length ));
For (var k in o)
If (new RegExp ("(" + k + ")"). test (fmt ))
Fmt = fmt. replace (RegExp. $1, (RegExp. $1. length = 1 )? (O [k])
: ("00" + o [k]). substr ("" + o [k]). length )));
Return fmt;
}
Used directly
Copy codeThe Code is as follows: new Date (time variable). Format ("yyyy-MM-dd HH: mm: ss ")
I hope this article will help you design javascript programs.