Skip to content

Instantly share code, notes, and snippets.

@knu2xs
Created June 17, 2014 16:46
Show Gist options
  • Select an option

  • Save knu2xs/efefe10dc294742b2030 to your computer and use it in GitHub Desktop.

Select an option

Save knu2xs/efefe10dc294742b2030 to your computer and use it in GitHub Desktop.
Date string formatted as yyyymmdd using javascript
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]); // padding
};
d = new Date();
d.yyyymmdd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment