javascript下ie7,ie8的Date Bug的解决 .
来源:互联网 发布:重庆正规网络整合营销 编辑:程序博客网 时间:2024/06/01 23:56
转自:http://blog.csdn.net/fjh658/article/details/8524530
ie9+, chrome firefox opera下 string到Date 使用 Date("2013-01-01"); 都是ok的。
但在ie7, ie8下 返回NaN
国外有人写了这样一个解决办法
- /**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})-(\d\d)-(\d\d)\s*$/,
- date = new Date(NaN), month,
- parts = isoExp.exec(dateStringInRange);
- if(parts) {
- month = +parts[2];
- date.setFullYear(parts[1], month - 1, parts[3]);
- if(month != date.getMonth() + 1) {
- date.setTime(NaN);
- }
- }
- return date;
- }
/**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})-(\d\d)-(\d\d)\s*$/, date = new Date(NaN), month, parts = isoExp.exec(dateStringInRange); if(parts) { month = +parts[2]; date.setFullYear(parts[1], month - 1, parts[3]); if(month != date.getMonth() + 1) { date.setTime(NaN); } } return date; }
使用如下:
parseISO8601("2013-01-01");
0 0
- javascript下ie7,ie8的Date Bug的解决
- javascript下ie7,ie8的Date Bug的解决 .
- javascript下ie7,ie8的Date Bug的解决
- 解决IE7和IE8的BUG方法
- CSS兼容:如何解决IE7和IE8的BUG
- 常用的ie6,ie7,ie8 css bug兼容性解决
- CSS 和JavaScript 在ie6 ie7 ie8和Firefox下bug兼容解决记录
- css 和javascript 在ie6 ie7 ie8和Firefox下bug兼容解决记录
- CSS 和JavaScript 在ie6 ie7 ie8和Firefox下bug兼容解决记录
- CSS兼容IE8,IE7 bug的解决方法
- IE8,IE7 Javascript获取 classname的方法
- IE7 IE8 的兼容性问题解决(微软)
- 如何解决IE7和IE8的兼容性问题
- jquery validate在ie8下的bug解决
- IE的CSS Bug列表(IE6,IE7和IE8)
- IE的CSS Bug列表(IE6,IE7和IE8)
- IE8 、 IE7 的兼容性问题
- ie7 slideup,mouseleave...的bug的解决
- C程序设计实验2
- 我们经常在一个activity中去start另一个activity,或者与另一个acitivity的结果进行交互(startActivityForResult)。但有没有想过可能会出现的permiss
- Android Silent Install Apk(Android 静默安装)
- nginx + tomcat 集群实现负载均衡
- 【.Net码农】List<T> 类
- javascript下ie7,ie8的Date Bug的解决 .
- java线程同步
- Eratosthenes筛选法计算质数
- Linux-CentOS 安装配置swftools
- java socket简单实例练习
- Cocos绑定Lua自定义类——Mac
- ubuntu /etc/rc.local下脚本不起作用
- Parallels Desktop 一流的Mac虚拟机
- php学习基础篇之数据类型转换、运算符、if 、switch 流程控制