LocalDateTime & Date相互转换

public Date fromLocalDateTime(LocalDateTime ldt){
	ZoneId zoneId = ZoneId.systemDefault();
    LocalDateTime localDateTime = LocalDateTime.now();
    ZonedDateTime zdt = localDateTime.atZone(zoneId);

    Date date = Date.from(zdt.toInstant());

    System.out.println("LocalDateTime = " + localDateTime);
    System.out.println("Date = " + date);
    return date ;
}	

public LocalDateTime fromDate(Date date){
    Instant instant = date.toInstant();
    ZoneId zoneId = ZoneId.systemDefault();
    LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
    System.out.println("Date = " + date);
    System.out.println("LocalDateTime = " + localDateTime);
    return localDateTime ;
}

详情: https://blog.csdn.net/hspingcc/article/details/73332380

你可能感兴趣的:(LocalDateTime & Date相互转换)