Created
January 12, 2016 04:00
-
-
Save suconghou/c854fdc15e06c0337023 to your computer and use it in GitHub Desktop.
Javascript辅助函数
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
// 格式化秒数到时间格式 | |
Number.prototype.formatTime=function(){ | |
// 计算 | |
var h=0,i=0,s=parseInt(this); | |
if(s>60){ | |
i=parseInt(s/60); | |
s=parseInt(s%60); | |
if(i > 60) { | |
h=parseInt(i/60); | |
i = parseInt(i%60); | |
} | |
} | |
// 补零 | |
var zero=function(v){ | |
return (v>>0)<10?"0"+v:v; | |
}; | |
return [zero(h),zero(i),zero(s)].join(":"); | |
}; | |
alert(Number(90).formatTime()) //00:01:30秒 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment