How do I get the difference between two Dates in JavaScript?

前端 未结 16 2549
北海茫月
北海茫月 2020-11-22 03:03

I\'m creating an application which lets you define events with a time frame. I want to automatically fill in the end date when the user selects or changes the start date.

16条回答
  •  温柔的废话
    2020-11-22 04:08

    If using moment.js, there is a simpler solution, which will give you the difference in days in one single line of code.

    moment(endDate).diff(moment(beginDate), 'days');
    

    Additional details can be found in the moment.js page

    Cheers, Miguel

提交回复
热议问题