JAVA8 LocalDateTime 各个类型转换(更新中..
作者:
YUTerry | 来源:发表于
2019-04-09 15:08 被阅读0次
long→LocalDateTime
public LocalDateTime longToLocalDateTime(Long milli) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
ZoneId zone = ZoneId.systemDefault();
return LocalDateTime.ofInstant(Instant.ofEpochMilli(milli),zone);
}
Date→LocalDateTime
public LocalDateTime dateToLocalDateTime(Date date) {
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
return instant.atZone(zoneId).toLocalDateTime();
}
LocalDateTime →Date
public Date localDateTimeTodate(LocalDateTime localDateTime) {
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}
本文标题:JAVA8 LocalDateTime 各个类型转换(更新中..
本文链接:https://www.haomeiwen.com/subject/pjepiqtx.html
网友评论