Date转LocalDateTime:
Date in = new Date(); LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault());
LocalDateTime转Date:
LocalDateTime ldt=LocalDateTime.now(); Date freezeTime = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
获取时间戳:
LocalDateTime currentTime = LocalDateTime.now(); Instant timestamp = currentTime.atZone(ZoneId.systemDefault()).toInstant(); long timestampMillis = timestamp.toEpochMilli();
LocalDateTime currentTime = LocalDateTime.now(); long timestampMillis = currentTime.toInstant(ZoneOffset.UTC).toEpochMilli();
LocalDateTime currentTime = LocalDateTime.now(); Duration duration = Duration.between(LocalDateTime.EPOCH, currentTime); long timestampMillis = duration.toMillis();
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END