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

前端 未结 13 2436
温柔的废话
温柔的废话 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

    I solved this question with solution below

      import org.joda.time.LocalDate;
      Date myDate = new Date();
      LocalDate localDate = LocalDate.fromDateFields(myDate);
      System.out.println("My date using Date" Nov 18 11:23:33 BRST 2016);
      System.out.println("My date using joda.time LocalTime" 2016-11-18);
    

    In this case localDate print your date in this format "yyyy-MM-dd"

提交回复
热议问题