Difference between two times in format (hh: mm: ss)

后端 未结 4 707
情书的邮戳
情书的邮戳 2021-01-01 04:08

I have two times, let say:

t1= \'05:34:01\' ;
t2= \'20:44:44\' ;

I want two evaluate difference between these two times in same format. Li

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-01 04:26

    I also used momentjs but with duration and got correct different between times:

    var t1 = moment('05:34:01', "HH:mm:ss");
    var t2 = moment('20:44:44', "HH:mm:ss");
    
    var start_date = moment(t1, 'YYYY-MM-DD HH:mm:ss');
    var end_date = moment(t2, 'YYYY-MM-DD HH:mm:ss');
    var duration = moment.duration(end_date.diff(t1));
    
    var t3 = duration.hours() + ":" + duration.minutes() + ":" + duration.seconds();
    alert(t3);
    console.log(duration.hours());
    console.log(duration.minutes());
    console.log(duration.seconds());
    

提交回复
热议问题