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

瀏覽器相容性

另見