This article describes the JavaScript implementation time format output FormatDate function. Share to everyone for your reference. Specifically as follows:
JavaScript does not provide a function to enter the date-time content format as FMT Tags:
Below is my time output function, when used directly into the label, call. The code is as follows
Copy Code code 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 (),//min
"S+": This.getseconds (),//sec
"q+": Math.floor (This.getmonth () + 3)/3),//Quarter
"S": This.getmilliseconds ()
Milliseconds
};
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])
: (("+ o[k]). substr ((" "" + o[k]). length));
return FMT;
}
Use directly with
Copy Code code as follows:
New Date (time variable). Format ("Yyyy-mm-dd HH:mm:ss")
I hope this article will help you with your JavaScript programming.