<script>
dfrom = datefrom.split("/");
dto = dateto.split("/");
//Checking Year Part;
if(parseInt(dfrom[2]) > parseInt(dto[2])){
alert("DateFrom Cannot greater than DateTo");
return false;
}
if((parseInt(dfrom[1]) > parseInt(dto[1])) && parseInt(dfrom[2]) == parseInt(dto[2])){
alert("DateFrom Cannot greater than DateTo");
return false;
}
if(parseInt(dfrom[0]) > parseInt(dto[0]) && (parseInt(dfrom[1]) == parseInt(dto[1])) && parseInt(dfrom[2]) == parseInt(dto[2])){
alert("DateFrom Cannot greater than DateTo");
return false;
}
</script>
这是我的脚本代码来比较日期和工作正常,但是当我检查2013年7月4日和2013年8月4日,它显示“DateFrom不会比DateTo更大的”和只有这些日期显示错误的结果。我的脚本或其他东西是否有错误?的Javascript:日期比较
任何帮助将是非常可观的。
使用javascript日期库。这很容易。 – ahren 2013-03-25 04:06:38
使用parseInt(东西,10),或'08'和'09'字符串将是八进制数字。 – kennebec 2013-03-25 04:20:07
写的代码是(半)无稽之谈。你有返回语句,但没有封闭函数。即使添加了正确的管道(并且从不使用parseInt与一个基数),代码似乎可以与提到的日期一起工作,但是谁又知道我是否以一种你没有的方式改变代码...... – jmbucknall 2013-03-25 04:28:18