Last active
August 29, 2015 13:55
-
-
Save nicklasos/8711611 to your computer and use it in GitHub Desktop.
So fucking JavaScript. Number format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('.'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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