js实现秒数换算成时分秒显示的代码
发布时间:2015-01-25 编辑:jiaochengji.com
本文介绍下,在javascript中将秒数换算成时分秒来显示的一段代码,有用到的朋友,可以参考学习下。
本文分享的这段代码,实现:
将秒数换算成时分秒,以友好的时间格式来显示。
代码:
<script language="javascript"> /** * 将秒数换成时分秒格式 * 整理:www.jbxue.com */ function formatSeconds(value) { var theTime = parseInt(value);// 秒 var theTime1 = 0;// 分 var theTime2 = 0;// 小时 // alert(theTime); if(theTime > 60) { theTime1 = parseInt(theTime/60); theTime = parseInt(theTime%60); // alert(theTime1+"-"+theTime); if(theTime1 > 60) { theTime2 = parseInt(theTime1/60); theTime1 = parseInt(theTime1%60); } } var result = ""+parseInt(theTime)+"秒"; if(theTime1 > 0) { result = ""+parseInt(theTime1)+"分"+result; } if(theTime2 > 0) { result = ""+parseInt(theTime2)+"小时"+result; } return result; } </script>
您可能感兴趣的文章:
js实现秒数换算成时分秒显示的代码
js时间转换(毫秒转换成日期时间)
基于jQuery的倒计时实现代码
js计算剩余天数二种方法
js倒计时与N秒后跳转页面的代码
js按指定格式显示日期时间的代码
js 倒计时多少秒后跳转页面的实例代码
js获取当前时间戳与日期比较
js代码实现时间日期和毫秒的互换
js 3秒后跳转页面实例代码
上一篇:js实现阿拉伯数字转换为中文大写的代码
下一篇:js编码、解码函数的实例参考
[关闭]