• 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] + "秒";
                    }
                }
            }
        }
  • 相关阅读:
    CRM详细介绍网址
    element上传多图片
    多图片上传WebForm
    MemCached原理
    Redis的原理
    Ninject用法详解
    SQLsugar和unity 的用法
    json中的转义字符的处理
    fiddler
    orm多表关系
  • 原文地址:https://www.cnblogs.com/wtao0730/p/15119758.html
Copyright © 2020-2023  润新知