Can you tell me why this is not working on Firefox (V 34 latest) ? It's working fine on all other browsers. 'DatePosted' is shown as Invalid Date.Why ? Any help would be highly appreciated.
你能告诉我为什么这没有在Firefox上工作(最新的v34)吗?它在所有其他浏览器上都运行良好。“datepost”显示为无效日期。为什么?非常感谢您的帮助。
//Get local time for everything:
data.Comments.forEach(function (x) {
x.DatePosted = new Date(x.DatePosted.toString().replace("T", " ") + " UTC");
});
Note : x.DatePosted : "2014-11-18T08:06:39.06"
注意:x。DatePosted:“2014 - 11 - 18岁t08:06:39.06”
1 个解决方案
#1
2
You dont need to replace the T
. It works without it (tested in Chrome and Firefox).
你不需要替换T. It工作没有它(在Chrome和Firefox中测试)。
After setting the Date object, get it into UTC.
设置日期对象后,将其输入UTC。
Working snippet below:
工作代码片段如下:
var myDate = new Date("2014-11-18T08:06:39.06");
// now set it to UTC
var myDateinUTC = Date.UTC(myDate.getFullYear(), myDate.getMonth(), myDate.getDate(), myDate.getHours(), myDate.getMinutes(), myDate.getSeconds(), myDate.getMilliseconds());
console.dir(myDateinUTC);
var myNewDate = new Date(myDateinUTC);
console.log(myNewDate.getMonth()); // just to test
#1
2
You dont need to replace the T
. It works without it (tested in Chrome and Firefox).
你不需要替换T. It工作没有它(在Chrome和Firefox中测试)。
After setting the Date object, get it into UTC.
设置日期对象后,将其输入UTC。
Working snippet below:
工作代码片段如下:
var myDate = new Date("2014-11-18T08:06:39.06");
// now set it to UTC
var myDateinUTC = Date.UTC(myDate.getFullYear(), myDate.getMonth(), myDate.getDate(), myDate.getHours(), myDate.getMinutes(), myDate.getSeconds(), myDate.getMilliseconds());
console.dir(myDateinUTC);
var myNewDate = new Date(myDateinUTC);
console.log(myNewDate.getMonth()); // just to test