How to calculate date difference in JavaScript?

前端 未结 18 2106
执笔经年
执笔经年 2020-11-22 03:41

I want to calculate date difference in days, hours, minutes, seconds, milliseconds, nanoseconds. How can I do it?

18条回答
  •  感动是毒
    2020-11-22 03:56

    If you are using moment.js then it is pretty simple to find date difference.

    var now  = "04/09/2013 15:00:00";
    var then = "04/09/2013 14:20:30";
    
    moment.utc(moment(now,"DD/MM/YYYY HH:mm:ss").diff(moment(then,"DD/MM/YYYY HH:mm:ss"))).format("HH:mm:ss")
    

提交回复
热议问题