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 |
瀏覽器相容性
載入中…