Calculate Time Difference with JavaScript

后端 未结 12 1117
有刺的猬
有刺的猬 2020-12-01 13:20

I have two HTML input boxes, that need to calculate the time difference in JavaScript onBlur (since I need it in real time) and insert the result to new input box.

F

12条回答
  •  独厮守ぢ
    2020-12-01 13:37

    TimeCount = function()
    {
        t++;
        var ms = t;
        if (ms == 99)
        {
            s++;
            t = 0;
            if ( s == 60)
            {
                m++;
                s = 0;
            }
        }
    
        Dis_ms = checkTime(ms);
        Dis_s = checkTime(s);
        Dis_m = checkTime(m);
        
        document.getElementById("time_val").innerHTML = Dis_m + ":" + Dis_s+ ":" + Dis_ms;
    }
    
    function checkTime(i) 
    {
      if (i<10) {
        i = "0" + i;
      }
      return i;
    } 

提交回复
热议问题