javaScript data 转换成 yyyy-mm-dd hh:mm:ss 的字符串

Life is short , play more!
本文来自lihao's Blog,转载请注明。

Date.prototype.yyyymmddhhmmss = function() {
var yyyy = this.getFullYear();
var mm = this.getMonth() < 9 ? "0" + (this.getMonth() + 1) : (this.getMonth() + 1); // getMonth() is zero-based var dd = this.getDate() < 10 ? "0" + this.getDate() : this.getDate(); var hh = this.getHours() < 10 ? "0" + this.getHours() : this.getHours(); var min = this.getMinutes() < 10 ? "0" + this.getMinutes() : this.getMinutes(); var ss = this.getSeconds() < 10 ? "0" + this.getSeconds() : this.getSeconds(); return "".concat(yyyy).concat("-").concat(mm).concat("-").concat(dd).concat(" ").concat(hh).concat(":").concat(min).concat(":").concat(ss); }; (new Date()).yyyymmddhhmmss() "2018-09-25 20:48:04"


发表评论

电子邮件地址不会被公开。 必填项已用*标注