如何将LocalDate转换为Instant? [英] How to convert a LocalDate to an Instant?
本文介绍了如何将LocalDate转换为Instant?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Java 8的新DateTime API。
I work with the new DateTime API of Java 8.
如何将LocalDate转换为Instant?
我得到一个例外,
How to convert a LocalDate to an Instant? I get an exception with
LocalDate date = LocalDate.of(2012, 2, 2);
Instant instant = Instant.from(date);
我不明白为什么。
推荐答案
为了将其转换为即时,您需要具有LocalDateTime实例,例如:
In order to convert it to an instant you need to have a LocalDateTime instance, e.g.:
LocalDate.now().atStartOfDay().toInstant(ZoneOffset.UTC)
这篇关于如何将LocalDate转换为Instant?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文