LocalDate、LocalDateTime与timestamp、Date的转换

时间:2025-04-02 20:03:37

转Date

LocalDate nowLocalDate = ();
Date date = (((8)).toInstant());

转Date

LocalDateTime localDateTime = ();
Date date = (((8)).toInstant());

转LocalDateTime(LocalDate)

Date date = new Date();
LocalDateTime localDateTime = ().atZone((8)).toLocalDateTime();
LocalDate localDate = ().atZone((8)).toLocalDate();

转时间戳

LocalDate localDate = ();
long timestamp = ((8)).toInstant().toEpochMilli();

转时间戳

LocalDateTime localDateTime = ();
long timestamp = ((8)).toEpochMilli();

6.时间戳转LocalDateTime(LocalDate)

long timestamp = ();
LocalDate localDate = (timestamp).atZone((8)).toLocalDate();
LocalDateTime localDateTime = (timestamp).atZone((8)).toLocalDateTime();