The example in this article describes the implementation of time format output FormatDate function in javascript. Share it with everyone for your reference. The details are as follows:
Javascript does not provide functions for inputting date and time content formats like the fmt tag:
Below is the time output function I downloaded. When using it, put it directly into the label and call it. The 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(), //hours
"m ": this.getMinutes(), //Minutes
"s": this.getSeconds(), //seconds
" 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])
: (("00" o[k]).substr(("" o[k]).length)));
Return fmt;
}
Use directly when using
new Date(time variable).Format("yyyy-MM-dd HH:mm :ss")
I hope this article will be helpful to everyone’s JavaScript programming design.