Convert java.util.Date to java.time.LocalDate

前端 未结 13 2648
温柔的废话
温柔的废话 2020-11-22 08:45

What is the best way to convert a java.util.Date object to the new JDK 8/JSR-310 java.time.LocalDate?

Date input = new Date();
Loca         


        
13条回答
  •  孤独总比滥情好
    2020-11-22 09:30

    You can convert in one line :

    public static LocalDate getLocalDateFromDate(Date date){
       return LocalDate.from(Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()));
    }
    

提交回复
热议问题