Temporal.PlainDate.prototype.daysInYear

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

daysInYear 訪問器屬性,是 Temporal.PlainDate 例項的一個屬性,它返回一個正整數,表示該日期所在年份的天數。該屬性是 日曆 相關的。

對於 ISO 8601 日曆,這通常是 365 天,閏年是 366 天。在其他日曆系統中,這個值很可能不同,尤其是在非太陽曆中。

daysInWeek 的設定器為 undefined。你無法直接更改此屬性。

示例

使用 daysInYear

js
const date = Temporal.PlainDate.from("2021-07-01");
console.log(date.daysInYear); // 365

const date2 = Temporal.PlainDate.from("2020-07-01");
console.log(date2.daysInYear); // 366; 2020 is a leap year

const date3 = Temporal.PlainDate.from("2021-07-01[u-ca=chinese]");
console.log(date3.daysInYear); // 354

const date4 = Temporal.PlainDate.from("2023-07-01[u-ca=chinese]");
console.log(date4.daysInYear); // 384; 2023 is a Chinese leap year

規範

規範
Temporal
# sec-get-temporal.plaindate.prototype.daysinyear

瀏覽器相容性

另見