首页 > 解决方案 > 默认的 Date.toLocalDateString() 基于什么?

问题描述

我正在尝试本地化我的 Web 应用程序,并且我考虑在我的前端脚本上使用 Date.toLocalDateString() ,因此它将基于用户位置。

根据 Mozzila MDN:

在不指定语言环境的基本使用中,返回默认语言环境和默认选项的格式化字符串。

他们提供了这个代码示例:

var date = new Date(Date.UTC(2012, 11, 12, 3, 0, 0));

// toLocaleDateString() without arguments depends on the implementation,
// the default locale, and the default time zone
console.log(date.toLocaleDateString());
// → "12/11/2012" if run in en-US locale with time zone America/Los_Angeles

但它没有说明默认语言环境和默认时区来自哪里。是按照系统设置吗?浏览器设置?知识产权?如果用户使用 VPN,它会改变吗?

标签: javascriptfrontenddom-manipulation

解决方案


推荐阅读