Temporal.PlainYearMonth.prototype.eraYear

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Thuộc tính truy cập eraYear của các thực thể Temporal.PlainYearMonth trả về một số nguyên không âm đại diện cho năm của year-month này trong kỷ nguyên, hoặc undefined nếu lịch không sử dụng kỷ nguyên (ví dụ: ISO 8601). Chỉ số năm thường bắt đầu từ 1 (phổ biến hơn) hoặc 0, và các năm trong một kỷ nguyên có thể giảm theo thời gian (ví dụ: Gregory TCN). eraeraYear cùng nhau xác định duy nhất một năm trong một lịch, giống như cách year làm. Nó phụ thuộc vào lịch.

Set accessor của eraYearundefined. Bạn không thể thay đổi thuộc tính này trực tiếp. Dùng phương thức with() để tạo một đối tượng Temporal.PlainYearMonth mới với giá trị mong muốn.

Để biết thông tin chung và thêm ví dụ, xem Temporal.PlainDate.prototype.eraYear.

Ví dụ

Sử dụng 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

Đặc tả

Specification
Temporal
# sec-get-temporal.plainyearmonth.prototype.erayear

Tương thích trình duyệt

Xem thêm