IE6-8中Date不支持toISOString的修复方法
人气:1
Date.prototype.toISOString方法是在ES5里添加的,ES3文档中没有,如下
这个方法在IE6/7/8中不支持,可按下面方式修复下
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';
}
}
相关:
http://msdn.microsoft.com/zh-cn/library/ie/ff925953%28v=vs.94%29.aspx
https:/https://img.qb5200.com/download-x/developer.mozilla.org/en-UShttps://img.qb5200.com/download-x/docs/Web/JavaScript/Reference/Global_Objects/Date
这个方法在IE6/7/8中不支持,可按下面方式修复下
复制代码 代码如下:
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';
}
}
相关:
http://msdn.microsoft.com/zh-cn/library/ie/ff925953%28v=vs.94%29.aspx
https:/https://img.qb5200.com/download-x/developer.mozilla.org/en-UShttps://img.qb5200.com/download-x/docs/Web/JavaScript/Reference/Global_Objects/Date
加载全部内容