IE8下,时间函数问题

最近做日历点播时遇到的一个问题,记录一下

new Date().getYear() 在chrome下返回的是116,而IE8下返回的是2016

导致日历初始化的时间在IE8下显示错误

 

另外附上一段网上摘录的兼容低版本IE的toISOString代码

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';
}

posted @ 2016-09-30 13:47  hahaha222  阅读(632)  评论(0编辑  收藏  举报