接下来看一下工具类的操作:
LocalDate today = LocalDate.now(); System.out.println(today.getYear()+"年是闰年吗? "+today.isLeapYear()); System.out.println(today.isBefore(LocalDate.of(2015,1,1))); System.out.println(today.atTime(LocalTime.now())); System.out.println("10天后 "+today.plusDays(10)); System.out.println("3周后 "+today.plusWeeks(3)); System.out.println("20个月后 "+today.plusMonths(20)); System.out.println("10天前 "+today.minusDays(10)); System.out.println("3周前 "+today.minusWeeks(3)); System.out.println("20月前 "+today.minusMonths(20)); System.out.println("月初是"+today.with(TemporalAdjusters.firstDayOfMonth())); LocalDate lastDayOfYear = today.with(TemporalAdjusters.lastDayOfYear()); System.out.println("年末是"+lastDayOfYear); Period period = today.until(lastDayOfYear); System.out.println("到年底是 "+period); System.out.println("还剩几个月 "+period.getMonths());