LocalDateTime转毫秒时间格式
LocalDateTime dateTimeE = LocalDateTime.of(2021, 4, 30, 14, 0, 0); // 定义年月日时分秒 long timeMillis= dateTimeE.toInstant(ZoneOffset.of("+8")).toEpochMilli(); System.out.println(timeMillis/1000); // 去掉毫秒
// 去掉毫秒等同于
long timeSecond = dateTime.toEpochSecond(ZoneOffset.of("+8"));
String formatDateTime = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
System.out.println(formatDateTime);
LocalDateTime localDateTime = new Date(1586843628000L).toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();
System.out.println(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));