这就是我所拥有的。
date = testInfoSelect.testDate;
console.log(date);
date = new Date(date);
console.log(date);
date = $.datepicker.formatDate('mm/dd/yy', date);
console.log(date);
这是 FF 中的控制台输出。
"Wed. February 24, 2016"
Invalid Date
"NaN/NaN/NaN"
这是 Chrome 中的控制台输出。
Wed. February 24, 2016
Wed Feb 24 2016 00:00:00 GMT-0500 (Eastern Standard Time)
02/24/2016
对于我的应用程序,我无法更改日期格式,即 testInfoSelect.testDate,在本例中为“2016 年 2 月 24 日星期三”。
我做了什么:
dateString String value representing a date. The string should be in a format recognized by the Date.parse() method (IETF-compliant RFC 2822 timestamps and also a version of ISO8601).
MDN 文档中最相似的日期格式是这样的:
Date.parse('Wed, 09 Aug 1995 00:00:00 GMT');
如何在不更改“Wed. February 24, 2016”格式的情况下在 FF 中得到正确的结果
谢谢
最佳答案
正如 @aeno 提到的,黑客可以:
new Date("Wed. February 24, 2016".replace('.', ''));
或
new Date("Wed. February 24, 2016".replace('.', ','));
就你的情况而言:
new Date(date.replace('.', ''));
要获取 GMT 时间,您可以执行以下操作:
> new Date(date.replace('.', '') + " GMT");
< Date 2016-02-24T00:00:00.000Z
FF、Chrome 和 Opera 的结果:
火狐浏览器:
▶ new Date("Wed. February 24, 2016".replace('.', '') + " GMT");
⯇ Date 2016-02-24T00:00:00.000Z
Chrome:
> new Date("Wed. February 24, 2016".replace('.', '') + " GMT");
<- Wed Feb 24 2016 01:00:00 GMT+0100 (CET)
歌剧:
>>> new Date("Wed. February 24, 2016".replace('.', '') + " GMT");
[+] Wed Feb 24 2016 01:00:00 GMT+0100
关于javascript - Firefox 无法使用 "Wed. October 28, 2015"等格式的 new Date(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29480312/