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;
//如果是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 }