Temporal.PlainDateTime.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 accessor eraYear của các instance Temporal.PlainDateTime trả về một số nguyên không âm đại diện cho năm của ngày này trong thời đại, hoặc undefined nếu lịch không sử dụng thời đại (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 thời đại có thể giảm theo thời gian (ví dụ: Gregorian BCE). era và eraYear cùng nhau xác định duy nhất một năm trong lịch, theo cách tương tự như year. Nó phụ thuộc vào lịch.
Set accessor của eraYear là undefined. Bạn không thể thay đổi thuộc tính này trực tiếp. Sử dụng phương thức with() để tạo một đối tượng Temporal.PlainDateTime mới với giá trị mới 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
const dt = Temporal.PlainDateTime.from("2021-07-01"); // ISO 8601 calendar
console.log(dt.eraYear); // undefined
const dt2 = Temporal.PlainDateTime.from("2021-07-01[u-ca=gregory]");
console.log(dt2.eraYear); // 2021
const dt3 = Temporal.PlainDateTime.from("-002021-07-01[u-ca=gregory]");
console.log(dt3.eraYear); // 2022; 0000 is used for the year 1 BC
const dt4 = Temporal.PlainDateTime.from("2021-07-01[u-ca=japanese]");
console.log(dt4.eraYear); // 3
Đặc tả
| Specification |
|---|
| Temporal> # sec-get-temporal.plaindatetime.prototype.erayear> |