zoukankan      html  css  js  c++  java
  • js把秒数转换为HH:MM:SS及时分秒格式

    
        /**
         * 转为HH:MM:SS
         * @param second
         * @returns {string}
         * @private
         */
          var _showTime = function (second) {
            if (second < 60) {
                if (second < 10) {
                    return "00:00:0" + second;
                } else {
                    return "00:00:" + second;
                }
            } else {
                var min_total = Math.floor(second / 60);	// 分钟
                var sec = Math.floor(second % 60);	// 余秒
                if (min_total < 60) {
                    if (min_total < 10) {
                        if (sec < 10) {
                            return "00:0" + min_total + ":0" + sec;
                        } else {
                            return "00:0" + min_total + ":" + sec;
                        }
                    } else {
                        if (sec < 10) {
                            return "00:" + min_total + ":0" + sec;
                        } else {
                            return "00:" + min_total + ":" + sec;
                        }
                    }
                } else {
                    var hour_total = Math.floor(min_total / 60);	// 小时数
                    if (hour_total < 10) {
                        hour_total = "0" + hour_total;
                    }
                    var min = Math.floor(min_total % 60);	// 余分钟
                    if (min < 10) {
                        min = "0" + min;
                    }
                    if (sec < 10) {
                        sec = "0" + sec;
                    }
                    return hour_total + ":" + min + ":" + sec;
                }
            }
        }
    
    
        /**
         * 转换时间格式为xx小时xx分xx秒
         * @param time HH:MM:SS
         */
        function changeTimeFormat(time) {
            var timeList = [];
            timeList = time.split(":");
            console.log(timeList)
            if (timeList[0] == '00') {
                if (timeList[1] == '00') {
                    return timeList[2] + "秒";
                } else {
                    if (timeList[2] == '00') {
                        return timeList[1] + "分";
                    } else {
                        return timeList[1] + "分" + timeList[2] + "秒";
                    }
                }
            } else {
                if (timeList[1] == '00') {
                    if (timeList[2] == '00') {
                        return timeList[0] + "小时";
                    } else {
                        return timeList[0] + "小时" + timeList[2] + "秒";
                    }
                } else {
                    if (timeList[2] == '00') {
                        return timeList[0] + "小时" + timeList[1] + "分";
                    } else {
                        return timeList[0] + "小时" + timeList[1] + "分" + timeList[2] + "秒";
                    }
                }
            }
        }
  • 相关阅读:
    MCS-51系列单片机和MCS-52系列单片机有何异同
    51单片机指令表
    ROM、PROM、EPROM、EEPROM、Flash ROM分别指什么?
    用最简单的办法轻松区分无源晶振和有源晶振
    CE310A
    夏普sharp复印机安装视频及教导
    SHARP AR-2048D/2348D
    SHARP 加粉1
    SHARP 加粉
    SQL SERVER BOOK
  • 原文地址:https://www.cnblogs.com/wtao0730/p/15119758.html
Copyright © 2011-2022 走看看