Intl.Locale.prototype.getCalendars()

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

getCalendars() 方法是 Intl.Locale 实例的一个方法,它返回该区域设置的一个或多个唯一的日历标识符列表。

注意: 在某些浏览器版本的某些版本中,此方法被实现为一个名为 calendars 的访问器属性。但是,因为它每次访问都会返回一个新的数组,所以现在它被实现为一个方法,以防止 locale.calendars === locale.calendars 返回 false 的情况。有关详细信息,请查看 浏览器兼容性表格

语法

js
getCalendars()

参数

无。

返回值

一个字符串数组,表示该 Locale 常用的所有日历,按偏好降序排序。如果 Locale 已经有了一个 calendar,则返回的数组包含该单个值。

支持的日历类型的列表,请参阅 Intl.supportedValuesOf()

示例

获取支持的日历

如果 Locale 对象还没有 calendargetCalendars() 会列出给定 Locale 常用的所有日历。有关显式设置 calendar 的示例,请参阅 calendar 示例

js
const arEG = new Intl.Locale("ar-EG");
console.log(arEG.getCalendars()); // ["gregory", "coptic", "islamic", "islamic-civil", "islamic-tbla"]
js
const jaJP = new Intl.Locale("ja-JP");
console.log(jaJP.getCalendars()); // ["gregory", "japanese"]

规范

规范
Intl Locale Info Proposal
# sec-Intl.Locale.prototype.getCalendars

浏览器兼容性

另见