alert(date2);//Sat Oct 29 0112 00:00:00 GMT+0100 (GMT Daylight Time)
alert(date1);//Fri Oct 12 2012 00:00:00 GMT+0100 (GMT Daylight Time)
if (date1.getTime()<date2.getTime()) {
alert('your date can not be earlier than today.');
}
我的问题是为什么我看不到警报?有什么问题吗?
编辑:
var today = new Date();
date2 = new Date(today.getYear(), today.getMonth(), today.getDate());
为什么年份显示为 0112?
最佳答案
您的日期 1 位于 2012 年,您的日期 2 位于 112 年,您测试日期 1 是否低于日期 2。 2012 年优于 112 年,所以这里没有任何问题
关于javascript - 检查日期是否早于今天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13122512/