Skip to content

Instantly share code, notes, and snippets.

@nicklasos
Last active August 29, 2015 13:55
Show Gist options
  • Save nicklasos/8711611 to your computer and use it in GitHub Desktop.
Save nicklasos/8711611 to your computer and use it in GitHub Desktop.
So fucking JavaScript. Number format
function dateFormat(daysAgo) {
var d = new Date();
daysAgo = daysAgo || 0;
d.setDate(d.getDate() - daysAgo);
var date = d.getDate(),
month = d.getMonth() + 1,
year = d.getFullYear();
return [date, ('0' + month).slice(-2), year].join('.');
}
// n = 3 => 03
// n = 10 => 10
("0" + (n + 1)).slice(-2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment