为什么我可以在 Chrome 中按区域设置格式化日期,而不能在我的 Javascript 应用程序中使用 toLocaleDateString() 按 Firefox 格式化日期?[复制]

Why can I format my dates by regional settings in Chrome but not Firefox in my Javascript application using toLocaleDateString()? [duplicate]

提问人:gib65 提问时间:10/19/2023 更新时间:10/19/2023 访问量:36

问:

我们正在开发一个 AngularJS 应用程序,我们希望在其中按用户所在地区格式化日期。我通过以下方式实现这一点:

row.StartLocal = new Date(start).toLocaleDateString();
row.EndLocal = new Date(end).toLocaleDateString();
...
<td>
    <span class="baseline-item-name">{{ b.StartLocal }} - {{ b.EndLocal }}</span>
</td>
...

我在 UI 中得到这个:

enter image description here

这对于格式为 MM/DD/YYYY 的“en-US”是正确的。

然后,我将我的地区(使用 Windows 10)切换为“en-UK”:

enter image description here

它在 UI 中没有效果。至少在 Chrome 中。另一方面,在Firefox中,我看到以下内容:

enter image description here

这对于格式为 DD/MM/YYYY 的“en-UK”是正确的。

所以我的问题是:为什么 toLocaleDateString() 在 Firefox 中有效,但在 Chrome 中无效?或者换句话说,有没有办法让 Chrome 像 Firefox 那样响应用户操作系统的区域设置,或者 Chrome 无法做到这一点?

javascript google-chrome firefox 日期格式 regional-settings

评论

0赞 Bergi 10/19/2023
您可能需要更改 Chrome 设置,而不是操作系统设置
0赞 Bergi 10/19/2023
另请参阅 stackoverflow.com/questions/69568454/...

答: 暂无答案