Temporal.PlainDate.prototype.toPlainYearMonth()

可用性有限

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

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

Temporal.PlainDate 实例的 toPlainYearMonth() 方法会返回一个新的 Temporal.PlainYearMonth 对象,该对象表示此日期在同一日历系统中的 year(年)和 month(月)。

语法

js
toPlainYearMonth()

参数

无。

返回值

一个表示此日期在同一日历系统中的 year(年)和 month(月)的新 Temporal.PlainYearMonth 对象。

示例

使用 toPlainYearMonth()

js
const date = Temporal.PlainDate.from("2021-07-01");
const yearMonth = date.toPlainYearMonth();
console.log(yearMonth.toString()); // 2021-07

规范

规范
Temporal
# sec-temporal.plaindate.prototype.toplainyearmonth

浏览器兼容性

另见