Last active
August 29, 2015 14:16
-
-
Save acrogenesis/73e3afc5330aa6789390 to your computer and use it in GitHub Desktop.
javascript Date toMySqlDate
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
d = new Date(); // => Thu Feb 26 2015 22:16:14 GMT-0600 (CST) | |
d.toMySQLDateTime(); // => 2015-02-26 22:16:14 | |
Date.prototype.toMySQLDateTime = function () { | |
function addZ(n) { | |
return (n<10? '0' : '') + n; | |
} | |
return this.getFullYear() + '-' + | |
addZ(this.getMonth() + 1) + '-' + | |
addZ(this.getDate()) + ' ' + | |
addZ(this.getHours()) + ':' + | |
addZ(this.getMinutes()) + ':' + | |
addZ(this.getSeconds()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment