Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 857 Bytes

getSecondsDiffBetweenDates.md

File metadata and controls

29 lines (20 loc) · 857 Bytes
标题 标签
getSecondsDiffBetweenDates(获取日期之间的秒数差) date(日期)

计算两个日期之间的差异(以秒为单位)。

  • 减去两个 Date 对象并除以一秒内的毫秒数,得到它们之间的差异(以秒为单位)。
const getSecondsDiffBetweenDates = (dateInitial, dateFinal) =>
  (dateFinal - dateInitial) / 1000;

调用方式:

getSecondsDiffBetweenDates(
  new Date('2020-12-24 00:00:15'),
  new Date('2020-12-24 00:00:17')
); // 2

应用场景

结果如下:

<iframe src="codes/javascript/html/getSecondsDiffBetweenDates.html"></iframe>