Created
November 2, 2017 18:36
-
-
Save gabrieldewes/d72f26333128a084e12dd027c0925e8b to your computer and use it in GitHub Desktop.
JS Date "yyyy-mm-dd hh:mm:ss" format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
"use strict"; | |
Date.prototype.toYyyymmddhhmmss = function() { | |
var yyyy = this.getFullYear(), | |
mm = this.getMonth() < 9 ? ("0" + (this.getMonth() + 1)) : (this.getMonth() + 1), | |
dd = this.getDate() < 10 ? ("0" + this.getDate()) : this.getDate(), | |
hh = this.getHours() < 10 ? ("0" + this.getHours()) : this.getHours(), | |
min = this.getMinutes() < 10 ? ("0" + this.getMinutes()) : this.getMinutes(), | |
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) | |
}; | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment