Skip to content

Instantly share code, notes, and snippets.

@gabrieldewes
Created November 2, 2017 18:36
Show Gist options
  • Save gabrieldewes/d72f26333128a084e12dd027c0925e8b to your computer and use it in GitHub Desktop.
Save gabrieldewes/d72f26333128a084e12dd027c0925e8b to your computer and use it in GitHub Desktop.
JS Date "yyyy-mm-dd hh:mm:ss" format
(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