Skip to content

Instantly share code, notes, and snippets.

@jessekinsman
Created January 24, 2015 22:47
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 jessekinsman/9962e33f497613320695 to your computer and use it in GitHub Desktop.
Save jessekinsman/9962e33f497613320695 to your computer and use it in GitHub Desktop.
Padding a one digit number in javascript
// One Digit returns string
function pad (n) {
return ("0" + n.toString()).slice(-2);
}
//Two digit returns string
function pad (n) {
return ("00" + n.toString()).slice(-3);
}
@jessekinsman
Copy link
Author

This is mostly used for times and so on when getting minutes from a date

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