Temporal.PlainDate.prototype.inLeapYear

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

Temporal.PlainDate 实例的 inLeapYear 访问器属性返回一个布尔值,指示该日期是否在闰年。闰年是指比平年多一天(由于闰日或闰月)的年份。这取决于 日历

对于 ISO 8601 日历,闰年是指能被 4 整除但不能被 100 整除的年份,除非该年份也能被 400 整除。对于 ISO 8601 日历,闰年有 366 天,而平年有 365 天。对于其他日历系统,规则可能不同,并且闰年可能会增加更多天(例如闰月)。

inLeapYear 的设置器为 undefined。你不能直接更改此属性。

示例

使用 inLeapYear

js
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

规范

规范
Temporal
# sec-get-temporal.plaindate.prototype.inleapyear

浏览器兼容性

另见