How to calculate date difference in JavaScript?

前端 未结 18 1782
执笔经年
执笔经年 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 04:08

    use Moment.js for all your JavaScript related date-time calculation

    Answer to your question is:

    var a = moment([2007, 0, 29]);   
    var b = moment([2007, 0, 28]);    
    a.diff(b) // 86400000  
    

    Complete details can be found here

提交回复
热议问题