IE6-8中Date不支持toISOString方法

来源:互联网 发布:域名权重查询 编辑:程序博客网 时间:2024/05/23 11:49

Date.prototype.toISOString方法是在ES5里添加的,ES3文档中没有,如下

 

这个方法在IE6/7/8中不支持,可按下面方式修复下

1

2

3

4

5

6

7

8

9

10

11

12

if (!Date.prototype.toISOString) {

    Date.prototype.toISOString = function() {

        function pad(n) { return n < 10 ? '0' + n : n }

        return this.getUTCFullYear() + '-'

            + pad(this.getUTCMonth() + 1) + '-'

            + pad(this.getUTCDate()) + 'T'

            + pad(this.getUTCHours()) + ':'

            + pad(this.getUTCMinutes()) + ':'

            + pad(this.getUTCSeconds()) + '.'

            + pad(this.getUTCMilliseconds()) + 'Z';

    }

}

 


0 0
原创粉丝点击