java.time.YearMonth.of(int year,Month month)
方法从年和月获取YearMonth的实例。
声明
以下是java.time.YearMonth.of(int year,Month month)
方法的声明。
public static YearMonth of(int year,Month month)
参数
year
- 要表示的年份,从MIN_YEAR
到MAX_YEAR
之间的值。month
- 表示月份。
返回值
年份,不是null
。
例外
DateTimeException
- 如果年份值无效。
例子
以下示例显示了java.time.YearMonth.of(int years,int months)
方法的用法。
package com.yiibai;
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