//LocalDateTime是日期处理类,可以设置到年月日时分秒,相当于LocalDate+LocalTime
//通过LocalDateTime.now()获取当前的时间,具体到年月日时分秒
LocalDateTime localDateTime = LocalDateTime.now();
//Zoneld用于标识在Instant和LocalDateTime之间的转换规则,同时也是时区ID
//通过ZoneId的systemDefault获取系统默认时区
ZoneId zoneId = ZoneId.systemDefault();
//LocalDateTime只是能显示本地日期和时间,没有时区
//ZoneIdDateTime要标识一个带时区的日期和时间
//ZonedDateTime相当于LocalDateTime+ZoneId
//通过LocalDateTime的atZone(new ZoneID)把LocalDateTime转换为ZoneDateTime
ZonedDateTime zonedDateTime =localDateTime.atZone(zoneId);
//Instant类用于在应用程序中记录事件的时间戳
//也即是把时间转化为一瞬间
//ZonedDateTime.toInstant是用于把ZonedDateTime转为Instant类型
Instant instant = zonedDateTime.toInstant();
//使用Date.from(new instant)方法,改为Date类型,该日期表示时间轴上与传递的瞬间相同的点。
Date date = Date.from(instant);
System.out.println(date);
对应的ZoneId、ZonedDateTime,Instant还有许多方法获取不同情况下的时间