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

匿名 (未验证) 提交于 2019-12-02 21:53:52
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     }

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!