它可以在其他网络浏览器中使用,但 IE11 返回无效日期。
为了调试我使用了下面的代码。
console.log('before - ' + date.value);
date.value = new Date(date.value);
console.log('after - ' + date.value);
IE11控制台
-1958-08-21 00:00:00.0 之前
之后-无效日期
Chrom 版本 75.0.3770.80
-1958-08-21 00:00:00.0之前
1958 年 8 月 21 日星期四 00:00:00 GMT-0700(太平洋夏令时间)之后
我认为
new Date("1958-08-21 00:00:00.0");
是使用该函数的非标准方式。
new Date("1958-08-21T00:00:00.0");
适用于 IE11。 (我添加了T
)。
根据MDN :
A string value representing a date, specified in a format recognized by the Date.parse() method (these formats are IETF-compliant RFC 2822 timestamps and also strings in a version of ISO8601).
Tôi là một lập trình viên xuất sắc, rất giỏi!