LocalDateTime & Date 상호 변환

827 단어
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

좋은 웹페이지 즐겨찾기