Count duration between two times after midnight

前端 未结 3 1931
逝去的感伤
逝去的感伤 2021-01-14 12:58

How to count duration between two times?

var start = moment(\'17:00\', \"HH:mm\");
var end = moment(\'02:15\', \"HH:mm\");
moment.duration(end.diff(start)).a         


        
3条回答
  •  忘掉有多难
    2021-01-14 13:31

    It's the simpliest way to count difference in one day:

    var start = moment('17:00', "HH:mm");
    var end = moment('02:15', "HH:mm");
    var duration = moment.duration(end.diff(start)).asHours();
    if (duration < 0) duration += 24;
    

提交回复
热议问题