Intl.Locale constructor is a standard built-in property of the Intl object that represents a Unicode locale identifier.

句法

new Intl.Locale(tag [, options])
					

参数

tag

The Unicode locale identifier string.

options

An object that contains configuration for the Locale. Keys are Unicode locale tags, values are valid Unicode tag values.

范例

基本用法

At its very simplest, the Intl.Locale constructor takes a locale identifier string as its argument:

let us = new Intl.Locale('en-US');
					

Using the Locale constructor with an options object

The constructor also takes an optional configuration object argument, which can contain any of several extension types. For example, set the hourCycle property of the configuration object to your desired hour cycle type, and then pass it into the constructor:

let us12hour = new Intl.Locale("en-US", {hourCycle: "h12"});
console.log(us12hour.hourCycle); // Prints "h12"
					

规范

规范
ECMAScript 国际化 API (ECMA-402)

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
Locale() 构造函数 Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 13.0.0
13.0.0
部分支持 12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. When other locales are specified, the Locale instance silently falls back to en-US . To make full ICU (locale) data available for versions prior to 13, see Node.js documentation on the --with-intl option and how to provide the data.

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: