s-day01--LocalDate的基本使用(代替Calender)--2
This commit is contained in:
@@ -24,5 +24,25 @@ public class Demo08 {
|
|||||||
System.out.println(ld1);
|
System.out.println(ld1);
|
||||||
LocalDate ld2 = ld.withMonth(12);
|
LocalDate ld2 = ld.withMonth(12);
|
||||||
System.out.println(ld2);
|
System.out.println(ld2);
|
||||||
|
|
||||||
|
// 4、把某个信息加多少: plusYears、plusMonths、plusDays、plusWeeks
|
||||||
|
LocalDate ld3 = ld.plusYears(2);
|
||||||
|
System.out.println(ld3);
|
||||||
|
LocalDate ld4 = ld.plusMonths(2);
|
||||||
|
System.out.println(ld4);
|
||||||
|
|
||||||
|
// 5、把某个信息减多少:minusYears、minusMonths、minusDays、minusWeeks
|
||||||
|
LocalDate ld5 = ld.minusYears(10);
|
||||||
|
System.out.println(ld5);
|
||||||
|
|
||||||
|
// 6、获取指定日期的LocalDate对象: public static LocalDate of(int year, int month, int dayOfMonth)
|
||||||
|
LocalDate ld6 = LocalDate.of(2028, 10, 1);
|
||||||
|
System.out.println(ld6);
|
||||||
|
|
||||||
|
// 7、判断2个日期对象,是否相等,在前还是在后: equals isBefore isAfter
|
||||||
|
System.out.println(ld5.equals(ld6));//false
|
||||||
|
System.out.println(ld5.isBefore(ld6));//true
|
||||||
|
System.out.println(ld5.isAfter(ld6));//false
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user