//时间格式“2004-11-22”和“2004-12-06” function compareDate(date1,date2){ var temp1=date1.split("-") var temp2=date2.split("-") for(var i=0;i<3;i++){ if(parseInt(temp1[i])<parseInt(temp2[i]))return -1 //date1<date2 else if(parseInt(temp1[i])>parseInt(temp2[i]))return 1//date1>date2 } return 0//date1=date2 }
zhaoxiaoyang(梅雪香) :老大,可以直接比较,刚才没调试好 谢谢
如果是这样呢? alert("2004-1-22"<"2004-10-06");
如果是这样呢?alert("2004-1-22"<"2004-09-06");
alert("2004-1-22"<"2004-09-06");这样是错误的. 应该这样: var d=new Date(); alert(d.setDate(2004-10-2)<d.setDate(2004-10-06));
//判断日期是否早于今天 if(year>=today.getYear()) { if(month>=(today.getMonth()+1)) { if(day>=today.getDate()) { alert("The day is before this day !!"); } else { alert("The day is before this day !!"); return 0; } } else { alert("The month is before this month !!"); return 0; } } else { alert("The year is before this year !!"); return 0; }
谢谢
//时间格式“2004-11-22”和“2004-12-06”
function compareDate(date1,date2){
var temp1=date1.split("-")
var temp2=date2.split("-")
for(var i=0;i<3;i++){
if(parseInt(temp1[i])<parseInt(temp2[i]))return -1 //date1<date2
else if(parseInt(temp1[i])>parseInt(temp2[i]))return 1//date1>date2
}
return 0//date1=date2
}
谢谢
alert("2004-1-22"<"2004-10-06");
应该这样:
var d=new Date();
alert(d.setDate(2004-10-2)<d.setDate(2004-10-06));
if(year>=today.getYear())
{
if(month>=(today.getMonth()+1))
{
if(day>=today.getDate())
{
alert("The day is before this day !!");
}
else
{
alert("The day is before this day !!");
return 0;
}
}
else
{
alert("The month is before this month !!");
return 0;
}
}
else
{
alert("The year is before this year !!");
return 0;
}