A-A+

javascript时间Date()不兼容IE7/IE8解决办法

2016年10月16日 前端设计 暂无评论 阅读 6 views 次

本文章给大家介绍关于javascript时间Date()不兼容IE7/IE8解决办法,有需碰到date不兼容的朋友可进入参考解决办法,有需要了解的朋友可参考。

IE7/8下,能把字符串格式数据转化为时间格式,找到了这个资料,有很多JS的小知识,大家可以保存起来,找时间看看,说不准哪天你做东西碰到问题了,也能在这里边找到解决办法。为了保险,我自己把这个页面也保存了一份。

在这里,我们可以看到,它给了一个把字符串格式的时间转化为时间格式的函数。

  1. An Extended ISO 8601 local Date format YYYY-MM-DD can be parsed to a Date with the following:-  
  2.   
  3. /**Parses string formatted as YYYY-MM-DD to a Date object. 
  4.   * If the supplied string does not match the format, an 
  5.   * invalid Date (value NaN) is returned. 
  6.   * @param {string} dateStringInRange format YYYY-MM-DD, with year in 
  7.   * range of 0000-9999, inclusive. 
  8.   * @return {Date} Date object representing the string. 
  9.   */  
  10.  function parseISO8601(dateStringInRange) {  
  11.    var isoExp = /^s*(d{4})-(dd)-(dd)s*$/,  
  12.        date = new Date(NaN), month,  
  13.        parts = isoExp.exec(dateStringInRange);  
  14.    if(parts) { //xiariboke.net  
  15.      month = +parts[2];  
  16.      date.setFullYear(parts[1], month - 1, parts[3]);  
  17.      if(month != date.getMonth() + 1) {  
  18.        date.setTime(NaN);  
  19.      }  
  20.    }  
  21.    return date;  
  22.  }  
标签:

给我留言