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.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn