毫秒或者秒转换为日期格式
程序员文章站
2022-12-20 08:14:40
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 }
上一篇: 如何制作出吸引潜在用户的网站?
下一篇: Android 实现锚点定位