Skip to content

Instantly share code, notes, and snippets.

@unbracketed
Last active August 29, 2015 14:06
Show Gist options
  • Save unbracketed/1c40e8ec2f2a0241961d to your computer and use it in GitHub Desktop.
Save unbracketed/1c40e8ec2f2a0241961d to your computer and use it in GitHub Desktop.
Javascript date formatter YYYYMMDD
Date.prototype.yyyymmdd = function() {
var yyyy = this.getFullYear().toString();
var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
var dd = this.getDate().toString();
return yyyy + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]);
};
d = new Date();
$('#today').html(d.yyyymmdd());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment