下面提到的代码用于比较日期。 date1 和 mydate 都有相似的值,但如果我比较它没有输入 if 循环。任何帮助表示赞赏
var date_arr = new Array( "Jan", "Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var Avl_date = document.getElementById("Available_Date").value;
var V_date1 = Avl_date.split('-');
var date1 = new Date (V_date1[2], date_arr.indexOf(V_date1[1]),V_date1[0]);
var myDate = new Date();
myDate.setHours(0,0,0);
//Thu Dec 04 2014 00:00:00 GMT+0530 (IST) --> date1
//Thu Dec 04 2014 00:00:00 GMT+0530 (IST) --> mydate
if(myDate.getTime() === date1.getTime())
{
//Not entering the loop
}
答案 0 :(得分:2)
您没有将myDate
的毫秒数设置为0
,因此它保持原来的毫秒数。使用:
myDate.setHours(0,0,0,0);
答案 1 :(得分:0)