本文主要是介绍秒转换成时长01:26形式显示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
function secondChange(time) {var tempTime = ''if (time) {var secondTime = parseInt(time);// 秒var minuteTime = 0;// 分var hourTime = 0;// 小时var result = ''if(secondTime > 60 || secondTime==60) {//如果秒数大于60,将秒数转换成整数//获取分钟,除以60取整数,得到整数分钟minuteTime = parseInt(secondTime / 60);//获取秒数,秒数取佘,得到整数秒数secondTime = parseInt(secondTime % 60);//如果分钟大于60,将分钟转换成小时if(minuteTime > 60) {//获取小时,获取分钟除以60,得到整数小时hourTime = parseInt(minuteTime / 60);//获取小时后取佘的分,获取分钟除以60取佘的分minuteTime = parseInt(minuteTime % 60);}}if(secondTime<10) {result = "0" + parseInt(secondTime) + "";} else {result = "" + parseInt(secondTime) + "";}if(minuteTime > 0) {result = parseInt(minuteTime)<10?"0" + parseInt(minuteTime) + ":" + result:"" + parseInt(minuteTime) + ":" + result;} else {result = '00:' + result}if(hourTime > 0) {result = "" + parseInt(hourTime) + ":" + result;}tempTime = result;}return tempTime
}
效果图如下:
这篇关于秒转换成时长01:26形式显示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!