A-A+
javascript时间Date()不兼容IE7/IE8解决办法
本文章给大家介绍关于javascript时间Date()不兼容IE7/IE8解决办法,有需碰到date不兼容的朋友可进入参考解决办法,有需要了解的朋友可参考。
IE7/8下,能把字符串格式数据转化为时间格式,找到了这个资料,有很多JS的小知识,大家可以保存起来,找时间看看,说不准哪天你做东西碰到问题了,也能在这里边找到解决办法。为了保险,我自己把这个页面也保存了一份。
在这里,我们可以看到,它给了一个把字符串格式的时间转化为时间格式的函数。
- An Extended ISO 8601 local Date format YYYY-MM-DD can be parsed to a Date with the following:-
- /**Parses string formatted as YYYY-MM-DD to a Date object.
- * If the supplied string does not match the format, an
- * invalid Date (value NaN) is returned.
- * @param {string} dateStringInRange format YYYY-MM-DD, with year in
- * range of 0000-9999, inclusive.
- * @return {Date} Date object representing the string.
- */
- function parseISO8601(dateStringInRange) {
- var isoExp = /^s*(d{4})-(dd)-(dd)s*$/,
- date = new Date(NaN), month,
- parts = isoExp.exec(dateStringInRange);
- if(parts) { //xiariboke.net
- month = +parts[2];
- date.setFullYear(parts[1], month - 1, parts[3]);
- if(month != date.getMonth() + 1) {
- date.setTime(NaN);
- }
- }
- return date;
- }