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

瀏覽器相容性

另見