• 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] + "秒";
                    }
                }
            }
        }
  • 相关阅读:
    五、批量插入
    四、操作BLOB类型字段
    三、使用PreparedStatement实现CRUD操作
    二、获取数据库连接
    一、JDBC概述
    最短平均码长(挑出假硬币问题的解法)
    信息量和信息熵
    洛谷P2114
    Servlet续(HttpServletRequest类和HttpServletResponse类)
    Servlet
  • 原文地址:https://www.cnblogs.com/wtao0730/p/15119758.html
Copyright © 2020-2023  润新知