欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

毫秒或者秒转换为日期格式

程序员文章站 2022-05-16 11:32:20
function timeToMillion(startStr, endStr) { var times; if(endStr){ var startT = new Date(startStr).getTime() var endT = new Date(endStr).getTime() time... ......
function timeToMillion(startStr, endStr) {
    var times;
    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;
    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 (day <= 9) day = '0' + day;
    // if (hour <= 9) hour = '0' + hour;
    // if (minute <= 9) minute = '0' + minute;
    // if (second <= 9) second = '0' + second;
    var endOutStr;
    if (parseInt(day) != 0) {
        endOutStr = day + "天" + hour + "小時" + minute + "分鐘"
    } else {
        if (parseInt(hour) != 0) {
            endOutStr = hour + "小時" + minute + "分鐘"
        } else {
            endOutStr = minute + "分鐘"
        }
    }
    return endOutStr
}

毫秒或者秒转换为日期格式