【发布时间】:2011-06-15 00:27:11
【问题描述】:
这是我的 javascript 代码:
var prevDate = new Date('1/25/2011'); // the string contains a date which
// comes from a server-side script
// may/may not be the same as current date
var currDate = new Date(); // this variable contains current date
currDate.setHours(0, 0, 0, 0); // the time portion is zeroed-out
console.log(prevDate); // Tue Jan 25 2011 00:00:00 GMT+0500 (West Asia Standard Time)
console.log(currDate); // Tue Jan 25 2011 00:00:00 GMT+0500 (West Asia Standard Time)
console.log(prevDate == currDate); // false -- why oh why
请注意,两个日期相同,但使用== 比较表明它们不相同。为什么?
【问题讨论】:
标签: javascript datetime date comparison