Last active
December 7, 2016 07:28
-
-
Save wangpin34/55302192bbe6a4a247d1a75f14e9100d to your computer and use it in GitHub Desktop.
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
/* | |
* 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