compareDate (d1, d2) { //判断两个日期的大小
let reg = new RegExp('-', 'g')
if(((new Date(d1.replace(reg, '/'))) > (new Date(d2.replace(reg, '/'))))){
console.log("第一个大");
return true;
}else{
console.log("第二个大");
return false;
}
}
this.compareDate("2022-02-12","2022-02-11")
文章介绍了如何使用JavaScript中的compareDate函数进行日期大小比较,通过替换字符串中的-为/并利用新Date对象实现日期比较。
3万+

被折叠的 条评论
为什么被折叠?



