Temporal.PlainDateTime.prototype.year
Temporal.PlainDateTime
实例的 year
访问器属性返回一个整数,表示此日期相对于特定日历纪元年份的开始的年份数。它依赖于日历。
year
的 set 访问器为 undefined
。您不能直接更改此属性。请使用 with()
方法创建一个具有所需新值的 Temporal.PlainDateTime
对象。
有关一般信息和更多示例,请参见 Temporal.PlainDate.prototype.year
。
示例
使用 year
js
const dt = Temporal.PlainDateTime.from("2021-07-01"); // ISO 8601 calendar
console.log(dt.year); // 2021
规范
规范 |
---|
Temporal # sec-get-temporal.plaindatetime.prototype.year |
浏览器兼容性
加载中…
另见
Temporal.PlainDateTime
Temporal.PlainDateTime.prototype.with()
Temporal.PlainDateTime.prototype.add()
Temporal.PlainDateTime.prototype.subtract()
Temporal.PlainDateTime.prototype.era
Temporal.PlainDateTime.prototype.eraYear
Temporal.PlainDateTime.prototype.yearOfWeek
Temporal.PlainDateTime.prototype.month
Temporal.PlainDateTime.prototype.day
Temporal.PlainDate.prototype.year