How to convert a LocalDate to an Instant?

前端 未结 2 574
轮回少年
轮回少年 2021-01-30 15:14

I work with the new DateTime API of Java 8.

How to convert a LocalDate to an Instant? I get an exception with

LocalDate date = LocalDate.of(2012, 2, 2);
         


        
2条回答
  •  时光取名叫无心
    2021-01-30 16:14

    In order to convert it to an instant you need to have a LocalDateTime instance, e.g.:

    LocalDate.now().atStartOfDay().toInstant(ZoneOffset.UTC)
    

提交回复
热议问题