在 IE 中使用此代码:
if(!Date.prototype.toISOString) Date.prototype.toISOString = function(){
var padZero = function(str, len){while(str.length < len) str = '0' + str; return str;};
var ret = padZero(''+this.getUTCFullYear(), 4)
+ '-' + padZero(''+this.getUTCMonth(), 2)
+ '-' + padZero(''+this.getUTCDate(), 2)
+ 'T' + padZero(''+this.getUTCHours(), 2)
+ ':' + padZero(''+this.getUTCMinutes(), 2)
+ ':' + padZero(''+this.getUTCSeconds(), 2)
+ 'Z';
alert(ret);
return ret;
}
我收到以下错误..
执行 urlrewrite 查询时出错:err:FORG0001: 类似日期时间的值“2012-00-05T09:09:46Z”的词法形式非法,月份字段的值 0 无效。 [第 42 行第 9 列]
我已经尝试了对月份参数的多次修复,但似乎无法正确解决。因此,我们将非常感谢任何帮助。
顺便说一句:上面的代码在 Firefox 中运行得很好..看看吧??
最佳答案
getUTCMonth()
从零开始,因此 0
是一月。您可以向其中添加 1 以形成日期字符串:
+ '-' + padZero(''+(this.getUTCMonth()+1), 2)
来自MDN docs :
getUTCMonth - Returns the month (0-11) in the specified date according to universal time.
关于Javascript/IE 日期时间错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14154341/