Skip to content

Instantly share code, notes, and snippets.

@viniciusdaniel
Last active May 25, 2017 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viniciusdaniel/b3164f0b9a83a213fb5ed84eaf9b6632 to your computer and use it in GitHub Desktop.
Save viniciusdaniel/b3164f0b9a83a213fb5ed84eaf9b6632 to your computer and use it in GitHub Desktop.
Simple datetime timestamp patch for javascript
if (Date.prototype.toDateTime === undefined) {
Date.prototype.toDateTime = function() {
// simple left zero
var lz = function ( v ) { return v < 10 ? '0' + v : '' + v; };
return this.getFullYear() + '/' +
lz( this.getMonth() + 1 ) + '/' +
lz( this.getDate() )+ ' ' +
lz( this.getHours() ) + ":" +
lz( this.getMinutes() ) + ":" +
lz( this.getSeconds() );
};
}
@viniciusdaniel
Copy link
Author

var now = new Date();
now.toDateTime(); // "2017/05/25 12:31:11"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment