Intl.Locale.prototype.getCalendars()
Intl.Locale 实例的 getCalendars() 方法返回此区域设置的一个或多个唯一日历标识符的列表。
¥The getCalendars() method of Intl.Locale instances returns a list of one or more unique calendar identifiers for this locale.
注意:在某些浏览器的某些版本中,此方法被实现为名为
calendars的访问器属性。但是,由于每次访问时都会返回一个新数组,因此现在将其实现为一种方法,以防止出现locale.calendars === locale.calendars返回false的情况。检查 浏览器兼容性表 了解详细信息。¥Note: In some versions of some browsers, this method was implemented as an accessor property called
calendars. However, because it returns a new array on each access, it is now implemented as a method to prevent the situation oflocale.calendars === locale.calendarsreturningfalse. Check the browser compatibility table for details.
语法
参数
返回值
¥Return value
表示 Locale 常用的所有日历的字符串数组,按优先级降序排序。如果 Locale 已有 calendar,则返回的数组包含该单个值。
¥An array of strings representing all calendars commonly used for the Locale, sorted in descending preference. If the Locale already has a calendar, then the returned array contains that single value.
以下是受支持的日历纪元类型的列表。
¥Below is a list of the supported calendar era types.
支持的日历类型
¥Supported calendar types
buddhist-
泰国佛历
chinese-
农历
coptic-
科普特历
dangi-
韩国传统日历
ethioaa-
埃塞俄比亚日历,Amete Alem(纪元约公元前 5493 年)
ethiopic-
埃塞俄比亚日历,Amete Mihret(大约纪元,公元 8 年)
gregory-
公历
hebrew-
传统希伯来历
indian-
印度日历
islamic-
伊斯兰历
islamic-umalqura-
伊斯兰历、Umm al-Qura
islamic-tbla-
伊斯兰历,表格(闰年 [2,5,7,10,13,16,18,21,24,26,29] - 天文纪元)
islamic-civil-
伊斯兰历,表格(闰年 [2,5,7,10,13,16,18,21,24,26,29] - 民用纪元)
islamic-rgsa-
伊斯兰历、沙特阿拉伯目击事件
iso8601-
ISO 日历(采用 ISO 8601 日历周规则的公历)
japanese-
日本皇历
persian-
波斯历
roc-
民用(算法)阿拉伯日历
islamicc-
民用(算法)阿拉伯日历
警告:
islamicc日历键已被弃用。请使用islamic-civil。¥Warning: The
islamicccalendar key has been deprecated. Please useislamic-civil.
示例
获取支持的日历
¥Obtaining supported calendars
如果 Locale 对象还没有 calendar,则 getCalendars() 列出给定 Locale 的所有常用日历。有关显式设置 calendar 的示例,请参阅 calendar 个例子。
¥If the Locale object doesn't have a calendar already, getCalendars() lists all commonly-used calendars for the given Locale. For examples of explicitly setting a calendar, see calendar examples.
const arEG = new Intl.Locale("ar-EG");
console.log(arEG.getCalendars()); // ["gregory", "coptic", "islamic", "islamic-civil", "islamic-tbla"]
const jaJP = new Intl.Locale("ja-JP");
console.log(jaJP.getCalendars()); // ["gregory", "japanese"]
规范
| Specification |
|---|
| Intl Locale Info Proposal # sec-Intl.Locale.prototype.getCalendars |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also
Intl.LocaleIntl.Locale.prototype.calendar- Unicode 区域设置数据标记语言规范中的 Unicode 日历标识符