How can I calculate the difference between two times that are in 24 hour format?

后端 未结 5 1896
死守一世寂寞
死守一世寂寞 2020-12-01 18:23

In JavaScript, how can I calculate the difference between two times that are in 24 hour format?

Example: Get how many hours elapsed from 08:00:00 to

5条回答
  •  孤城傲影
    2020-12-01 19:08

    try this way

    var time_start = new Date();
    var time_end = new Date();
    var value_start = "06:00:00".split(':');
    var value_end = "23:00:00".split(':');
    
    time_start.setHours(value_start[0], value_start[1], value_start[2], 0)
    time_end.setHours(value_end[0], value_end[1], value_end[2], 0)
    
    time_end - time_start // millisecond 
    

提交回复
热议问题