Temporal.PlainDate.prototype.inLeapYear
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 inLeapYear của các instance Temporal.PlainDate trả về một boolean cho biết ngày này có phải là năm nhuận không. Năm nhuận là năm có nhiều ngày hơn (do ngày nhuận hoặc tháng nhuận) so với năm thông thường. Nó phụ thuộc vào lịch.
Đối với lịch ISO 8601, năm nhuận là năm chia hết cho 4, ngoại trừ các năm chia hết cho 100, trừ khi năm cũng chia hết cho 400. Đối với lịch ISO 8601, năm nhuận có 366 ngày, trong khi năm thông thường có 365 ngày. Đối với các hệ thống lịch khác, các quy tắc có thể khác nhau, và năm nhuận có thể có nhiều ngày được thêm vào hơn (chẳng hạn như tháng nhuận).
Set accessor của inLeapYear là undefined. Bạn không thể thay đổi thuộc tính này trực tiếp.
Ví dụ
>Sử dụng inLeapYear
const date = Temporal.PlainDate.from("2021-07-01");
console.log(date.inLeapYear); // false
console.log(date.daysInYear); // 365
console.log(date.monthsInYear); // 12
const date2 = Temporal.PlainDate.from("2020-07-01");
console.log(date2.inLeapYear); // true
console.log(date2.daysInYear); // 366
console.log(date2.monthsInYear); // 12
const date3 = Temporal.PlainDate.from("2021-07-01[u-ca=chinese]");
console.log(date3.inLeapYear); // false
console.log(date3.daysInYear); // 354
console.log(date3.monthsInYear); // 12
const date4 = Temporal.PlainDate.from("2023-07-01[u-ca=chinese]");
console.log(date4.inLeapYear); // true
console.log(date4.daysInYear); // 384
console.log(date4.monthsInYear); // 13
Đặc tả
| Specification |
|---|
| Temporal> # sec-get-temporal.plaindate.prototype.inleapyear> |