java.time.MonthDay.atYear() 方法
描述
java.time.MonthDay.atYear(int year) 方法将此月-日与年结合起来创建一个 LocalDate。
声明
以下是 java.time.MonthDay.atYear(int year) 方法的声明。
public LocalDate atYear(int year)
参数
year − 要使用的年份,从 MIN_YEAR 到 MAX_YEAR。
返回值
由本月-日和指定年份组成的本地日期,不为空。
异常
DateTimeException − 如果年份超出有效年份范围。
示例
下面的例子展示了 java.time.MonthDay.atYear(int year) 方法的使用。
package com.tutorialspoint;
import java.time.LocalDate;
import java.time.MonthDay;
public class MonthDayDemo {
public static void main(String[] args) {
MonthDay time = MonthDay.parse("--12-30");
LocalDate date = time.atYear(2017);
System.out.println(date);
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
2017-12-30

