Get the time difference between two datetimes

前端 未结 19 2004
花落未央
花落未央 2020-11-22 05:25

I know I can do anything and some more envolving Dates with momentjs. But embarrassingly, I\'m having a hard time trying to do something that seems simple: geting the differ

19条回答
  •  鱼传尺愫
    2020-11-22 06:01

    In ES8 using moment, now and start being moment objects.

    const duration = moment.duration(now.diff(start));
    const timespan = duration.get("hours").toString().padStart(2, '0') +":"+ duration.get("minutes").toString().padStart(2, '0') +":"+ duration.get("seconds").toString().padStart(2, '0');
    

提交回复
热议问题