new data();为创建一个新的时间
const today = new Date();
console.log(today)
可以获取对应的年月日 时分秒
console.log(today.getFullYear(),today.getMonth()+1,today.getDate(),today.getHours(),today.getMinutes())
因为月份是从0开始算起,所以获取月份要加1
data转换成时间戳
在data类后面加上.time就变成时间戳了
通过时间戳判断某个日期是否为同一天
const targetDate = new Date(timestamp);
const today = new Date();
const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate()).getTime();
const targetDateStart = new Date(targetDate.getFullYear(), targetDate.getMonth(), targetDate.getDate()).getTime();
如果todayStart 和targetDateStart 相等就是同一天否则则不是
代码意思就是把根据年月日(不能添加时间和秒否则不一样)生成新的时间戳,然后比对时间戳判断是不是在同一天