zoukankan      html  css  js  c++  java
  • 毫秒或者秒转换为日期格式

    function timeToMillion(startStr, endStr) {
            var times;
          //如果是2个参数就是时间差
    if (endStr) { var startT = new Date(startStr).getTime() var endT = new Date(endStr).getTime() times = (endT - startT) / 1000
          // 如果是一个参数,参数值是秒数
    } else { times = startStr } var day, hour, minute,endOutStr; if (times > 0) { // console.log(times) day = Math.floor(times / (60 * 60 * 24)); hour = Math.floor(times / (60 * 60)) - (day * 24); minute = Math.floor(times / 60) - (day * 24 * 60) - (hour * 60); // second = Math.floor(times) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60); if (parseInt(day) != 0) { endOutStr = day + "天" + hour + "小時" + minute + "分鐘" } else { if (parseInt(hour) != 0) { endOutStr = hour + "小時" + minute + "分鐘" } else { endOutStr = minute + "分鐘" } } }else{ endOutStr = 0 } // if (day <= 9) day = '0' + day; // if (hour <= 9) hour = '0' + hour; // if (minute <= 9) minute = '0' + minute; // if (second <= 9) second = '0' + second; return endOutStr }

    /*
    * timeToRemaining(seconds)秒數,返回剩餘的大概時間,有天數直接返回天數,沒天數有小時直接返回小時數,沒有小時數有分鐘數直接返回分鐘數,
    * 沒有分鐘數直接返回傳入的秒數
    *
    **/ 
    
    function timeToRemaining(seconds) {
        var times = parseInt(seconds) || 0;
        var day, hour, minute, second, endOutStr;
        if (times && times > 0) {
            day = Math.floor(times / (60 * 60 * 24));
            hour = Math.floor(times / (60 * 60)) - (day * 24);
            minute = Math.floor(times / 60) - (day * 24 * 60) - (hour * 60);
            // second = Math.floor(times) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
            second = times
    
            if (parseInt(day) != 0) {
                return endOutStr = day + "天"
            } else {
                if (parseInt(hour) != 0) {
                    return endOutStr = hour + "小時"
                } else {
                    if (parseInt(minute) != 0) {
                        return endOutStr = minute + "分鐘"
                    }else{
                        return endOutStr = second + "秒"
                    }
                }
            }
        } else {
            return endOutStr = 0
        }
    }

  • 相关阅读:
    元组-琢磨已久的购物车程序
    学习使我充实自己-列表具备的功能
    很高兴今天用PYTHON3写了三级菜单程序!
    python内建模块shlex将普通字符串编码成符合linux shell的字符串
    HTTPS能登陆,HTTP不行
    linux shell判断输入的是哪个不可见字符,例如^X(Ctrl-X)
    TI CC3200做ETSI EN 300 328 认证
    使用systemd-resolved的系统中DNS来源优先级
    systmed-timesyncd中NTP服务器地址来源优先级
    markdown的简单应用实例
  • 原文地址:https://www.cnblogs.com/-walker/p/8652316.html
Copyright © 2011-2022 走看看