貼文討論:求助我要做一個計時器小程序




var time_val;
      var go_timer;
      var stop_time = 0;
      function add_zero(num, digit) {
       let numString = String(num)
       while (numString.length < digit) {
        numString = "0" + numString
       }
       return numString
      }

go_timer = new Date();
        time_val = setInterval(() => {
         let temp_timer = new Date().getTime() - go_timer.getTime();
         let day = add_zero(Math.floor(temp_timer / 1000 / 60 / 60 / 24), 2);
         let hours = add_zero(Math.floor(temp_timer / 1000 / 60 / 60) % 24, 2);
         let minutes = add_zero(Math.floor(temp_timer / 1000 / 60) % 60, 2);
         let seconds = add_zero(Math.floor(temp_timer / 1000 % 60), 2);
         let milliseconds = add_zero(temp_timer % 1000, 3);
         var timers = [day, hours, minutes, seconds, milliseconds];
         console.log(timers[0] + "天\n" + timers[1] + "時\n" + timers[2] + "分\n" + timers[3] + "秒\n" + timers[4] + "毫秒");
        }, 1)

此人尚未填寫簡介。