Java8 LocalDatetime与 java.util.Date 互转

Date to LocalDateTime

Date todayDate = new Date();

LocalDateTime localDate = todayDate.toInstant().atZone( ZoneId.systemDefault()).toLocalDateTime();

LocalDateTime to Date

LocalDateTime localDateTime = LocalDateTime.now();

Date date = Date.from( localDateTime.atZone( ZoneId.systemDefault()).toInstant());

posted @ 2023-03-27 15:36  jason_bo  阅读(58)  评论(0编辑  收藏  举报