Temporal.PlainYearMonth.prototype.eraYear
Temporal.PlainYearMonth 例項的 **eraYear** 訪問器屬性返回一個非負整數,表示此年月在其紀年中對應的年份,如果日曆不使用紀年(例如 ISO 8601),則返回 undefined。年份索引通常從 1(更常見)或 0 開始,並且紀年中的年份可能隨時間減小(例如,公曆的公元前)。era 和 eraYear 一起可以唯一地標識日曆中的一年,就像 year 一樣。它取決於 日曆。
eraYear 的設定訪問器是 undefined。您不能直接更改此屬性。請使用 with() 方法建立一個具有所需新值的 Temporal.PlainYearMonth 新物件。
有關一般資訊和更多示例,請參閱 Temporal.PlainDate.prototype.eraYear。
示例
使用 eraYear
js
const ym = Temporal.PlainYearMonth.from("2021-07"); // ISO 8601 calendar
console.log(ym.eraYear); // undefined
const ym2 = Temporal.PlainYearMonth.from("2021-07-01[u-ca=gregory]");
console.log(ym2.eraYear); // 2021
const ym3 = Temporal.PlainYearMonth.from("-002021-07-01[u-ca=gregory]");
console.log(ym3.eraYear); // 2022; 0000 is used for the year 1 BC
const ym4 = Temporal.PlainYearMonth.from("2021-07-01[u-ca=japanese]");
console.log(ym4.eraYear); // 3
規範
| 規範 |
|---|
| Temporal # sec-get-temporal.plainyearmonth.prototype.erayear |
瀏覽器相容性
載入中…