LocalDateTime使用
DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//获取当前时间
LocalDateTime date=LocalDateTime.now();
System.out.println("YEAR"+date.getYear());
System.out.println("MONTH"+date.getMonth());
System.out.println("DAY"+date.getDayOfMonth());
System.out.println("HOUR"+date.getHour());
System.out.println("MINUTES"+date.getMinute());
System.out.println("SECOND"+date.getSecond());
System.out.println("localDateTime"+dateTimeFormatter.format(date));
//当前年的第一天
LocalDateTime firstdayOfYear =date.with(TemporalAdjusters.firstDayOfNextYear());
System.out.println("firstdayOfYear"+dateTimeFormatter.format(firstdayOfYear));
//当前年的最后一天
LocalDateTime enddayOfYear =date.with(TemporalAdjusters.lastDayOfYear());
System.out.println("enddayOfYear"+dateTimeFormatter.format(enddayOfYear));
//获取当前月的第一天
LocalDateTime firstdayOfMonth =date.with(TemporalAdjusters.firstDayOfMonth());
System.out.println("firstdayOfMonth"+dateTimeFormatter.format(firstdayOfMonth));
//获取当前月的最后一天
LocalDateTime endDayOfMonth=date.with(TemporalAdjusters.lastDayOfMonth());
System.out.println("endDayOfMonth"+dateTimeFormatter.format(endDayOfMonth));
//获取下个月第一天
LocalDateTime firstdayOfNextMonth=date.with(TemporalAdjusters.firstDayOfNextMonth());
System.out.println("firstdayOfNextMonth"+dateTimeFormatter.format(firstdayOfNextMonth));
//月增加一个月
LocalDateTime addMonth=date.plusMonths(1);
System.out.println("addMonth"+dateTimeFormatter.format(addMonth));
//月减少一个月
LocalDateTime lessenMonth=date.minusMonths(1);
System.out.println("lessenMonth"+dateTimeFormatter.format(lessenMonth));
//天增加一天
LocalDateTime addOfDay=date.plusDays(1);
System.out.println("addOfDay"+dateTimeFormatter.format(addOfDay));
//天减少一天
LocalDateTime lessOfDay=date.minusDays(1);
System.out.println("lessOfDay"+dateTimeFormatter.format(lessOfDay));