Temporal.PlainMonthDay.prototype.calendarId
Temporal.PlainMonthDay
实例的 calendarId
访问器属性返回一个字符串,表示用于解释内部 ISO 8601 日期的 日历。
有关常用日历类型的列表,请参阅Intl.supportedValuesOf()
。
calendarId
的 set 访问器是 undefined
。您不能直接更改此属性。没有明显的方法可以创建一个具有不同日历且表示相同月日的新的 Temporal.PlainMonthDay
对象,因此您需要先使用 toPlainDate()
将其转换为 Temporal.PlainDate
对象,然后更改日历,最后再转换回来。
示例
使用 calendarId
js
const md = Temporal.PlainMonthDay.from("07-01");
console.log(md.calendarId); // "iso8601"; default
const md2 = Temporal.PlainMonthDay.from("2021-07-01[u-ca=chinese]");
console.log(md2.calendarId); // "chinese"
更改 calendarId
js
const md = Temporal.PlainMonthDay.from("07-01");
const newMD = md
.toPlainDate({ year: 2021 })
.withCalendar("chinese")
.toPlainMonthDay();
console.log(newMD.monthCode, newMD.day); // "M05" 22
const newMD2 = md
.toPlainDate({ year: 2022 })
.withCalendar("chinese")
.toPlainMonthDay();
console.log(newMD2.monthCode, newMD2.day); // "M06" 3
规范
规范 |
---|
Temporal # sec-get-temporal.plainmonthday.prototype.calendarid |
浏览器兼容性
加载中…