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

浏览器兼容性

另见