let startDate = new Date('2020-10-07'); let endDate = new Date('2020-11-12'); const DAY_IN_MS = 24 * 60 * 60 * 1000; let timeDiff = Math.abs(endDate.getTime() - startDate.getTime()); let dayDiff = Math.ceil(timeDiff / DAY_IN_MS); console.log('Difference is: ' + dayDiff + ' days');
getTime() method returns the number of milliseconds since the Unix Epoch.
getTime() always uses UTC for time representation. For example, a client browser in one timezone,
getTime() will be the same as a client browser in any other timezone.
You can use this method to help assign a date and time to another Date object. This method is functionally equivalent to the valueOf() method.