Javascript 如何从mobile设置navigator区域设置
我正在尝试测试我为在聊天中显示时间戳而构建的实用程序函数。我希望它可以从每个国家访问,并基于navigator.language动态呈现 我在手机上测试时遇到问题。在桌面上,我可以在Chrome的高级设置中编辑默认语言。你知道这是从哪里得到的移动,如果是这样,我可以在哪里改变它Javascript 如何从mobile设置navigator区域设置,javascript,date,navigator,Javascript,Date,Navigator,我正在尝试测试我为在聊天中显示时间戳而构建的实用程序函数。我希望它可以从每个国家访问,并基于navigator.language动态呈现 我在手机上测试时遇到问题。在桌面上,我可以在Chrome的高级设置中编辑默认语言。你知道这是从哪里得到的移动,如果是这样,我可以在哪里改变它 export function getLocaleTimestamp (showSeconds) { const locale = navigator.language || navigator.userLangua
export function getLocaleTimestamp (showSeconds) {
const locale = navigator.language || navigator.userLanguage;
const date = new Date();
let localeFormat = null;
const options = {
hour: 'numeric',
minute: 'numeric',
...(showSeconds && { second: 'numeric' })
};
localeFormat = new Intl.DateTimeFormat(locale,
options
).format;
const formatedDate = localeFormat(date);
return formatedDate;
}
不久前,我在测试我为我们美国客户所做的更改时遇到了同样的问题。由于Chrome使用来自操作系统的时区,所以要做到这一点,我必须更改系统日期时间,并连接到USA VPN。所以我假设它也需要IP连接/或网络时间线。 同样值得在Chrome开发工具new Date.tolocalesting'en-US',{timeZone:'Asia/Jakarta'}//preferedtimezone中尝试 如果你还有别的办法,请告诉我
有用的链接stackoverflow.com/a/16449343/1225070和stackoverflow.com/a/18612568/1225070。谢谢你的建议。