Skip to content

Instantly share code, notes, and snippets.

@wangpin34
Last active December 7, 2016 07:28
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 wangpin34/55302192bbe6a4a247d1a75f14e9100d to your computer and use it in GitHub Desktop.
Save wangpin34/55302192bbe6a4a247d1a75f14e9100d to your computer and use it in GitHub Desktop.
/*
* Add pre zero to number which is less than 10, and then return the final string
* @ num Number 0
*/
function addPreZero(num) {
if(arguments.length == 0) num = 0;
if(num < 10){
return '0' + num;
}
return '' + num;
}
function getTimeNum(date) {
if(!date || !(date instanceof Date)){
date = new Date();
}
return date.getFullYear()
+ addPreZero((date.getMonth()+1))
+ addPreZero(date.getDate())
+ addPreZero(date.getHours())
+ addPreZero(date.getMinutes())
+ addPreZero(date.getSeconds())
+ date.getMilliseconds();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment