Get the time difference between two datetimes

前端 未结 19 2246
花落未央
花落未央 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 05:50

    This should work fine.

    var now  = "04/09/2013 15:00:00";
    var then = "02/09/2013 14:20:30";
    
    var ms = moment(now,"DD/MM/YYYY HH:mm:ss").diff(moment(then,"DD/MM/YYYY HH:mm:ss"));
    var d = moment.duration(ms);
    
    console.log(d.days() + ':' + d.hours() + ':' + d.minutes() + ':' + d.seconds());
    

提交回复
热议问题