1. Date转ZonedDateTime
ZonedDateTime.ofInstant(<Date类型的对象>.toInstant(), ZoneId.systemDefault());
2. ZoneDatedTime转Date
Date.from(<ZonedDateTime类型的对象>.toInstant());
3. 系统当前日期: ZoneDatedTime转Date --> 返回Date类型
Date.from(ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS).toInstant())
4. 系统当前时间: ZoneDatedTime转String--> 返回String类型 hh:mm:ss
ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS).format(DateTimeFormatter.ISO_LOCAL_TIME)
5. 从ZoneDateTime中获取年、月、日、时、分、秒, 实际是转成了LocalDateTime,从LocalDateTime中获取
// 获取系统当前时间
ZonedDateTime zonedDateTimeNow = ZonedDateTime.now();
// 转LocalDateTime
LocalDateTime localDateTime = zonedDateTimeNow.toLocalDateTime();
// 从LocalDateTime中获取年月日时分秒
int year = localDateTime.get(ChronoField.YEAR);
int mon = localDateTime.get(ChronoField.MONTH_OF_YEAR);
int day = localDateTime.get(ChronoField.DAY_OF_MONTH);
int hour = localDateTime.get(ChronoField.HOUR_OF_DAY);
int min = localDateTime.get(ChronoField.MINUTE_OF_HOUR);
int sec = localDateTime.get(ChronoField.SECOND_OF_MINUTE);
// 字符串格式转换: 不足2位的补0, 如: 08时08分08秒
String h = String.format("%02d", hour);
String m = String.format("%02d", min);
String s = String.format("%02d", sec);
// 指定年月日时分秒,创建LocalDateTime
// LocalDateTime localDateTime = LocalDateTime.of(2020, 10, 1, 8, 28, 38);