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

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

    first, it's easy to convert a Date to an Instant

    Instant timestamp = new Date().toInstant(); 
    

    Then, you can convert the Instant to any date api in jdk 8 using ofInstant() method:

    LocalDateTime date = LocalDateTime.ofInstant(timestamp, ZoneId.systemDefault()); 
    
    0 讨论(0)
提交回复
热议问题