[原创] 时间戳差转化为时间

 var data1 = Date.parse(new Date())  //当前时间戳
 var data2 = (new Date(2018, 6, 6, 0, 0, 0)).getTime();   //7月6日的时间戳
 function getDifValue(nowtimestamp, beforetimestamp){
            var difValue = nowtimestamp - beforetimestamp;
            var day = Math.floor(difValue / 1000 / 60 / 60 / 24);//天
            difValue = difValue % (1000 * 60 * 60 * 24);
            var hour = Math.floor(difValue / 1000 / 60 / 60);//小时
            difValue = difValue % (1000 * 60 * 60);
            var min = Math.floor(difValue / 1000 / 60);//分钟
            difValue = difValue % (1000 * 60);
            var second = Math.floor(difValue / 1000);
            return "超时:" + day + "年" + hour + "小时" + min + "分钟" + second + "秒"
        }
        getDifValue(data1,data2);

效果如下
这里写图片描述

接下来做多个超时运算,

你可能感兴趣的:([原创] 时间戳差转化为时间)