Skip to content

Instantly share code, notes, and snippets.

@premii
Created April 18, 2014 18:39
Show Gist options
  • Save premii/11058388 to your computer and use it in GitHub Desktop.
Save premii/11058388 to your computer and use it in GitHub Desktop.
Pad Zeros : add leading zero to seconds, minutes, months and dates
var padZero = function(v) {
return ('0'+v).split('').reverse().splice(0,2).reverse().join('');
}
// OR
var padZero = function(v){
return ('0'+v).substr(-2);
}
padZero(6) // 06
padZero(13) // 13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment