在做报表统计时,需要对指定时间内的数据做统计,则需要使用到时间日期API
在此使用的是java.util.Date的完美私生子LocalDate类
- LocalDate方法介绍
- now() : 从默认时区的系统时钟中获取当前日期。
LocalDate l = LocalDate.now();
System.out.println(l.plusYears(1));
2020-05-17
Process finished with exit code 0
2. now(ZoneId) : 从指定时区的系统时钟中获取当前日期。
LocalDate l = LocalDate.now(ZoneId.of("-05:00"));
System.out.println(l.plusYears(1));
3. now(Clock) : 从指定时钟获取当前日期。
LocalDate l = LocalDate.now(Clock.systemUTC());
4. of(int,Month,int) : 从年、月和日获取LocalDate实例。
System.out.println(LocalDate.of(0, Month.MAY, 1));
0000-05-01
Process