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

前端 未结 13 2554
温柔的废话
温柔的废话 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条回答
  •  萌比男神i
    2020-11-22 09:31

    I have had problems with @JodaStephen's implementation on JBoss EAP 6. So, I rewrote the conversion following Oracle's Java Tutorial in http://docs.oracle.com/javase/tutorial/datetime/iso/legacy.html.

        Date input = new Date();
        GregorianCalendar gregorianCalendar = (GregorianCalendar) Calendar.getInstance();
        gregorianCalendar.setTime(input);
        ZonedDateTime zonedDateTime = gregorianCalendar.toZonedDateTime();
        zonedDateTime.toLocalDate();
    

提交回复
热议问题