javascript - 为什么 Intl.DateTimeFormat 在 IE 浏览器中不起作用
问题描述
我有这个 JS 功能:
var TodayDate = new Intl.DateTimeFormat(en-US, { day: 'numeric', month: 'long', year: 'numeric' }).format(Date.now())
输出是:
铬:2020 年 4 月 19 日
边缘:2020 年 4 月 19 日
火狐 = 2020 年 4 月 19 日
但在 IE(Internet Explorer)中根本不起作用,为什么?
解决方案
它仅适用于 Internet Explorer 11,没有更早的版本。
toLocaleDateString应该给出相同的结果,并且在 IE 5.5+ 上可用
const dateTimeFormat = new Intl.DateTimeFormat('en-US', { day: 'numeric', month: 'long', year: 'numeric' }).format(Date.now())
console.log(dateTimeFormat)
const localeDateString = new Date().toLocaleDateString('en-US', { day: 'numeric', month: 'long', year: 'numeric' })
console.log(localeDateString)
推荐阅读
- python - 操作 pandas 数据框以显示所需的输出
- sql-server - 如何在sql中指定打印
- linux - 按内容搜索文件,可能涉及 -exec 命令和管道 2>
- javascript - 单击循环按钮时按钮文本更改
- c# - Elastic Search .NET Core 不成功的 Post 低级调用
- android - DeepLinks 未打开正确的活动
- node.js - 启动 nodejs 时出错:openssl 配置失败
- .htaccess - htaccess RewriteRule 带有文字问号(不是查询字符串)
- iis - ASP NET CORE 2.1 IIS 本地主机连接被拒绝
- webpack - 多主题设置 - webpack / Vue-cli