Java8-LocalDate、LocalDateTime、Date、时间戳的转化
- 转Date
- 转Date
- 转LocalDate,LocalDateTime
- 转时间戳
- 转时间戳
- 6.时间戳转为LocalDate(LocalDateTime)
转Date
public static Date LocalDate2Date(LocalDate localDate) {
ZoneId zone = ();
Instant instant = ().atZone(zone).toInstant();
return (instant);
}
转Date
public static Date LocalDateTime2Date(LocalDateTime localDateTime) {
ZoneId zone = ();
Instant instant = (zone).toInstant();
return (instant);
}
转LocalDate,LocalDateTime
public static LocalDate date2LocalDate(Date date) {
ZoneId currentZone = ();
Instant instant = ();
return (currentZone).toLocalDate();
}
转时间戳
public static long toLocalDateStamp(LocalDate date) {
ZoneId zone = ();
return (zone).toInstant().toEpochMilli();
}
转时间戳
public static long toLocalDateTimeStamp(LocalDateTime date) {
return ((8)).toEpochMilli();
}
6.时间戳转为LocalDate(LocalDateTime)
public static LocalDateTime toLocalDateTime(long timeStamp) {
ZoneId zone = ();
return (timeStamp * 1000).atZone(zone).toLocalDateTime();
}