1、Timestamp(long)转成日期
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
LocalDateTime localDateTime = timestamp.toLocalDateTime(); //之后就可以通过java8 新API操作时间了
localDateTime.toLocalDate();
Date date = new Date(timestamp.getTime()); //以前的Timetamp转日期的写法,然后通过SimpleDateFormatter转化了
2、Date与LocalDateTime的互相转换
/** * LocalDateTime转Date * @param localDateTime * @return */ public static Date localDateTime2Date(LocalDateTime localDateTime){ ZoneId zoneId = ZoneId.systemDefault(); ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId); Date date = Date.from(zonedDateTime.toInstant()); return date; } /** * Date转LocalDateTime * @param date * @return */ public static LocalDateTime Date2LocalDateTime(Date date){ Instant instant = date.toInstant(); ZoneId zoneId = ZoneId.systemDefault(); LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime(); return localDateTime; }