Here is one way : (这是一种方法 :)
const date1 = new Date('7/13/2010');
const date2 = new Date('12/15/2010');
const diffTime = Math.abs(date2 - date1);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
console.log(diffDays);
Observe that we need to enclose the date in quotes. (请注意,我们需要将日期用引号引起来。) The rest of the code gets the time difference in milliseconds and then divides to get the number of days. (其余代码获得时差(以毫秒为单位),然后除以天数。) Date expects mm/dd/yyyy format. (日期应采用mm / dd / yyyy格式。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…