比较javascript中的日期:IE 8异常
我尝试了以下代码来比较两个日期比较javascript中的日期:IE 8异常,javascript,date,internet-explorer-8,Javascript,Date,Internet Explorer 8,我尝试了以下代码来比较两个日期 //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 fal
//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;
}
//以下检查验证输入的日期格式是否正确,是否有效
如果(s|period==“”| |!date|u format.exec(s|period))
{
警报(“请将开始日期输入为YYYY-MM-DD”);
返回false;
}
//接下来,我想检查s_周期是否大于'2013-06-30'
如果((新日期(s_period).getTime())<(新日期(“2013-07-01”).getTime())
{
警报(“从2013年7月1日起提供的统计数据”);
返回false;
}
上面关于在2013-06-30之后选择日期的警告在Firefox中被调用,但在IE8中没有。有人能推荐我需要添加的额外代码,使其在所有浏览器版本中都能正常工作吗?
谢谢试试Date.parse
e、 g
if((日期解析(s_期))<(日期解析(“2013-07-01”))
这是您的整个程序吗?什么是date\u form.exec?date\u format=/^(\d{4})\-(\d{2})\-(\d{2})$/。将日期与正则表达式date_formatWorks for me进行比较:感谢向我展示该函数。但是,它在IE8上仍然不起作用。该函数在Firefox b/c上工作,我尝试了以下方法:d_s_period=Date.parse(“2013-01-01”);文件编写(d_s_期间);它在IE 8中打印NaN,但在Firefox上打印1356998400000将日期格式更改为“2013/01/01”(使用/代替-)
if((Date.parse(s_period)) < (Date.parse("2013-07-01")))