Intl.Locale.prototype.calendar
Intl.Locale 例項的 calendar 訪問器屬性會返回此區域設定的日曆型別。
描述
儘管世界上大多數地區都使用公曆,但世界各地存在幾種區域日曆時代。支援的日曆型別列表,請參閱 Intl.supportedValuesOf()。
calendar 屬性的值在構造時設定,可以透過區域設定識別符號的 ca 鍵或 Intl.Locale() 建構函式的 calendar 選項來設定。如果兩者都存在,則後者具有優先權;如果兩者都不存在,則該屬性值為 undefined。
calendar 的設定訪問器為 undefined。您無法直接更改此屬性。
示例
與其他區域設定子標籤一樣,日曆型別可以透過區域設定字串或建構函式的配置物件引數新增到 Intl.Locale 物件中。
透過區域設定字串新增日曆型別
在 Unicode 區域設定字串規範中,calendar 是一個“擴充套件子標籤”。這些子標籤添加了關於區域設定的附加資料,並使用 -u 擴充套件鍵新增到區域設定識別符號中。要將日曆型別新增到傳遞給 Intl.Locale() 建構函式的初始區域設定識別符號字串,請先新增 -u 擴充套件鍵(如果不存在)。接下來,新增 -ca 擴充套件以指示您正在新增日曆型別。最後,新增日曆時代型別。
js
const locale = new Intl.Locale("fr-FR-u-ca-buddhist");
console.log(locale.calendar); // "buddhist"
透過配置物件引數新增日曆型別
Intl.Locale() 建構函式有一個可選的配置物件引數,其中可以包含多種擴充套件型別,包括日曆。將配置物件的 calendar 屬性設定為您想要的日曆時代,然後將其傳遞給建構函式。
js
const locale = new Intl.Locale("fr-FR", { calendar: "buddhist" });
console.log(locale.calendar); // "buddhist"
規範
| 規範 |
|---|
| ECMAScript® 2026 國際化 API 規範 # sec-Intl.Locale.prototype.calendar |
瀏覽器相容性
載入中…
另見
Intl.LocaleIntl.Locale.prototype.getCalendars()- Unicode Calendar Identifier in the Unicode locale data markup language spec