Java8 java.util.Date conversion to java.time.ZonedDateTime

后端 未结 4 706
轮回少年
轮回少年 2020-12-07 21:44

I am getting the following exception while trying to convert java.util.Date to java.time.LocalDate.

java.time.DateTimeException: U         


        
4条回答
  •  星月不相逢
    2020-12-07 22:27

    To transform an Instant to a ZonedDateTime, ZonedDateTime offers the method ZonedDateTime.ofInstant(Instant, ZoneId). So

    So, assuming you want a ZonedDateTime in the default timezone, your code should be

    ZonedDateTime d = ZonedDateTime.ofInstant(calculateFromDate.toInstant(),
                                              ZoneId.systemDefault());
    

提交回复
热议问题