我尝试过以下代码来比较两个日期
//the following check validates that the date is entered in the right format and it works
if(s_period=="" || !date_format.exec(s_period))
{
alert("Please enter start date as YYYY-MM-DD");
return false;
}
//next, i want to check if s_period is greater than '2013-06-30'
if((new Date(s_period).getTime()) < (new Date("2013-07-01").getTime()))
{
alert("Stat available from 2013-07-01");
return false;
}
上述用于选择2013-06-30之后的日期的警报会在Firefox中调用,但不会在IE8上调用。有人可以建议我需要添加的其他代码,以使其适用于所有浏览器版本吗? 感谢
答案 0 :(得分:1)
尝试Date.parse http://msdn.microsoft.com/en-us/library/ie/k4w173wk(v=vs.94).aspx
e.g。
if((Date.parse(s_period)) < (Date.parse("2013-07-01")))