Java中的MonthDay atYear()方法
使用atYear()Java中MonthDay类中的方法,可以将MonthDay与年份组合以创建LocalDate。此方法需要一个参数,即year,它返回通过结合MonthDay和year创建的LocalDate。
演示此过程的程序如下:
示例
import java.time.*;
public class Demo {
public static void main(String[] args) {
MonthDay md = MonthDay.parse("--02-22");
System.out.println("The MonthDay is: " + md);
LocalDate ld = md.atYear(2019);
System.out.println("The LocalDate is: " + ld);
}
}输出结果
The MonthDay is: --02-22 The LocalDate is: 2019-02-22
现在让我们了解上面的程序。
首先显示MonthDay。然后,使用该atYear()方法将MonthDay与年份合并以创建LocalDate。演示此代码段如下所示:
MonthDay md = MonthDay.parse("--02-22");
System.out.println("The MonthDay is: " + md);
LocalDate ld = md.atYear(2019);
System.out.println("The LocalDate is: " + ld);热门推荐
10 高一祝福语简短 励志
11 立秋节气简短祝福语
12 简短公司周年祝福语大全
13 中考感言简短祝福语大全
14 体育老师简短祝福语
15 干杯生日祝福语简短独特
16 特别简短的祝福语老师
17 朋友坐车走了祝福语简短
18 给英雄的祝福语简短