Java日期时间类

  • LocalDateTime 日期 + 时间
  • LocalDate 日期
  • LocalDate 时间
    常用日期操作:
LocalDateTime now = LocalDateTime.now();  //当前时间

LocalDateTime plusYearsTime = now.plusYears(1);  //加一年
LocalDateTime plusMonthsTime = now.plusMonths(1);  //加一月
LocalDateTime plusHoursTime = now.plusDays(1);  //加一天
LocalDateTime plusHourTime = now.plusHours(1);  //加一小时
LocalDateTime plusMinutesTime = now.plusMinutes(1);  //加一分钟
LocalDateTime plusSecondsTime = now.plusSeconds(1);  //加一秒

LocalDateTime minusYearsTime = now.minusYears(1); //减一年
LocalDateTime minusMonthsTime = now.minusMonths(1);  //减一月
LocalDateTime minusDaysTime = now.minusDays(1);  //减一天
LocalDateTime minusHoursTime = now.minusHours(1);   //减一小时
LocalDateTime minusMinutesTime = now.minusMinutes(1); //减一分钟
LocalDateTime minusSecondsTime = now.minusSeconds(1);  //减一秒钟