Js 时间戳与当前时间 得出相差天,时,分

2020-04-13  本文已影响0人  吴小冷
    /**
    * 计算时间戳与当前时间的差值
    * @param start_time 开始时间戳
    */
    function calculateDiffTime(start_time) {
        if(!parseInt(start_time)) return "-";
        var endTime = Math.round(new Date() / 1000);

        var timeDiff = endTime - start_time
        var day = parseInt(timeDiff / 86400);
        var hour = parseInt((timeDiff % 86400) / 3600);
        var minute = parseInt((timeDiff % 3600) / 60);

        day = day?(day+'天'):'';
        hour = hour?(hour+"时"):'';
        minute = minute?(minute+"分"):'';
        return day + hour + minute;
    }

上一篇 下一篇

猜你喜欢

热点阅读