首页 > 其他 > 详细

把字符串格式的时间转化为时间格式的函数

时间:2015-02-10 18:29:15      阅读:314      评论:0      收藏:0      [点我收藏+]
 1 /**Parses string formatted as YYYY-MM-DD to a Date object.
 2   * If the supplied string does not match the format, an
 3   * invalid Date (value NaN) is returned.
 4   * @param {string} dateStringInRange format YYYY-MM-DD, with year in
 5   * range of 0000-9999, inclusive.
 6   * @return {Date} Date object representing the string.
 7   */
 8  function parseISO8601(dateStringInRange) {
 9    var isoExp = /^\s*(\d{4})-(\d\d)-(\d\d)\s*$/,
10        date = new Date(NaN), month,
11        parts = isoExp.exec(dateStringInRange);
12  
13    if(parts) {
14      month = +parts[2];
15      date.setFullYear(parts[1], month - 1, parts[3]);
16      if(month != date.getMonth() + 1) {
17        date.setTime(NaN);
18      }
19    }
20    return date;
21  }

解决IE7/IE8下javascript的时间函数Date()不兼容

来源:http://digdeeply.org/archives/04251973.html

把字符串格式的时间转化为时间格式的函数

原文:http://www.cnblogs.com/ivxpingg/p/4284410.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!