- java.time 包類
- java.time - 主頁
- java.time - 時鐘
- java.time - 時長
- java.time - 時間
- java.time - 本地日期
- java.time - 本地日期和時間
- java.time - 本地時間
- java.time - 月日
- java.time - 偏移日期時間
- java.time - 偏移時間
- java.time - 週期
- java.time - 年
- java.time - 年月
- java.time - 分割槽日期時間
- java.time - 分割槽識別符號
- java.time - 分割槽偏移量
- java.time 包列舉
- java.time - 月份
- java.time 有用資源
- java.time - 討論
java.time.YearMonth.of() 方法示例
描述
java.time.YearMonth.of(int 年份, 月份) 根據年份和月份獲取 YearMonth 例項。
宣告
以下是 java.time.YearMonth.of(int 年份, 月份) 方法的宣告:
public static YearMonth of(int year,Month month)
引數
年份 − 要表示的年份,介於 MIN_YEAR 至 MAX_YEAR 之間。
月份 − 要表示的年份中的月份。
返回值
YearMonth,非空。
異常如果年份值無效,則會丟擲 DateTimeException 異常。
示例
以下示例展示了 java.time.YearMonth.of(int 年份, int 月份) 方式的使用:
package com.tutorialspoint;
import java.time.Month;
import java.time.YearMonth;
public class YearMonthDemo {
public static void main(String[] args) {
YearMonth year = YearMonth.of(2017,Month.DECEMBER);
System.out.println(year);
}
}
讓我們編譯並執行上述程式,將生成以下結果:
2017-12
廣告