乐趣区

关于java:LocalDateTime与Date类型间转化

将 LocalDateTime 转换为 Date:

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

将 Date 转换为 LocalDateTime:

Date date = new Date();
LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
退出移动版