获取当前年月日
LocalDate now = LocalDate.now(); //2022-12-18
int year = LocalDate.now().getYear(); //2022
int month = LocalDate.now().getMonth().getValue(); //12
int day = LocalDate.now().getDayOfMonth(); //18
获取当前时分秒
LocalTime now = LocalTime.now(); //19:21:55.125
int hour = LocalTime.now().getHour(); //19
int minute = LocalTime.now().getMinute(); //21
int second = LocalTime.now().getSecond(); //55
获取当前年-月-日 时:分:秒
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
String nowTime = dtf.format(now);
System.out.println(dateFormat); //2022-12-18 19:21:55
日期时间之间格式相互转换
String nowTime = "2022-12-18 19:21:55";
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(nowTime);
String dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒").format(date);
System.out.println(dateFormat); //2022年12月18日 19时21分55秒