javascript - time counter since start date and time

前端 未结 3 809
南方客
南方客 2020-12-17 05:35

I have a new business, where I just hired someone to work for me, I am trying to make it easy for her to track her time, so I created a clock in button, that creates a recor

3条回答
  •  庸人自扰
    2020-12-17 06:02

    Get the difference between two dates by subtracting them:

    var duration = end - start;
    

    This will give you the number of milliseconds between the dates. You can use the milliseconds to figure out hours, minutes, and seconds. Then it's just a matter of string manipulation and writing the value to the page. To update the timer once per second, use setInterval():

    setInterval(writeDuration, 1000);
    

提交回复
热议问题