A-A+

Date.parse Firefox返回Nan的错误

2015年06月27日 编程技术 暂无评论

利用 firefox 对 ecshop 进行兼职测试时,却意外发现了一个问题,就是对 firefox 对于时间,比如 2015-07-01,这样的时间格式不感冒,直接返回 Nan 的错误,小虎博客最终的解决方法是直接将符号“-”替换成了“/”,问题解决解决,实例代码如下:

  1. <script type=”text/javascript”>  
  2. <!–  
  3. var inputDate=”2015-07-01 15:55:00″;inputDate=inputDate.replace(“-”, “/”).replace(“-”, “/”);var nowDate=new Date();//alert(Date.parse(inputDate))//alert(Date.parse(nowDate))if(Date.parse(inputDate)<Date.parse(nowDate)){alert(“对不起,输入时间不能晚于当前时间!”);}  
  4. // –>  
  5. </script>  
标签:

给我留言