30秒学会 JavaScript 片段 · 2019年11月3日

30秒学会 JavaScript 片段 – isSameDate

Check if a date is the same as another date.

Use Date.prototype.toISOString() and strict equality checking (===) to check if the first date is the same as the second one.

代码片段

const isSameDate = (dateA, dateB) => dateA.toISOString() === dateB.toISOString();

使用样例

isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 20)); // true