//LocalDateTime转时间戳
LocalDateTime.now.toInstant(ZoneOffset.of(“+8)).toEpochMilli();
//时间戳转 LocalDateTime
LocalDateTime dateTime = Instant.ofEpochMilli(mills).atZone(ZoneId.systemDefault()).toLocalDateTime()
//Date转LocalDateTime
LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(),ZoneId.systemDefault());
//LocalDateTime转Date
Date date = Date.from( localDateTime.atZone(ZoneId.systemDefault()).toInstant());java.time.LocalDateTime与时间戳与Date相互转换
最新推荐文章于 2024-12-04 08:00:00 发布
该文详细介绍了在Java中如何进行LocalDateTime、时间戳以及Date类型之间的相互转换,包括使用toInstant()、ofEpochMilli()、atZone()和toInstant()等方法。
4万+

被折叠的 条评论
为什么被折叠?



