1.获取时间:
LocalDateTime time = LocalDateTime.now();
2.获取相对于当前时间的前几天后几天的时间,可以用来做定时任务用:
LocalDateTime changeTime = time.plusDays(-1);
3.将时间格式化成想要的格式(yyyy-MM-dd HH:mm:ss):
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String format = changeTime.format(formatter);