时间戳转LocalDateTime
long time = System.currentTimeMillis();
// 将时间戳转换为Instant对象
Instant instant = Instant.ofEpochMilli(time);
// 将Instant对象转换为LocalDateTime对象
LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
字符串转LocalDateTime
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 将字符串解析为 LocalDateTime
LocalDateTime dateTime = LocalDateTime.parse(deviceParameterDetailDTO.getStartTime(), formatter);
LocalDateTime转时间戳
// 将 LocalDateTime 转换为 Instant
Instant instant = dateTime.atZone(ZoneId.systemDefault()).toInstant();
// 获取时间戳(毫秒)
long timestamp = instant.toEpochMilli();