问题描述
转换JodaTime的最简单方法是 对象?
What is the simplest way to convert a JodaTime LocalDate
to java.util.Date
object?
推荐答案
JodaTime
要转换JodaTime的到,do
JodaTime
To convert JodaTime's org.joda.time.LocalDate
to java.util.Date
, do
Date date = localDate.toDateTimeAtStartOfDay().toDate();
要转换JodaTime的到,do
To convert JodaTime's org.joda.time.LocalDateTime
to java.util.Date
, do
Date date = localDateTime.toDate();
JavaTime
要转换Java8的到,do
JavaTime
To convert Java8's java.time.LocalDate
to java.util.Date
, do
Date date = Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
要转换Java8的到 ,do
To convert Java8's java.time.LocalDateTime
to java.util.Date
, do
Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
您可能会尝试使用 LocalDateTime#toInstant(ZoneOffset)
,但是没有一个直接的API来获取系统默认区域偏移。
You might be tempted to shorten it with LocalDateTime#toInstant(ZoneOffset)
, but there isn't a direct API to obtain the system default zone offset.
要转换Java8的到,do
To convert Java8's java.time.ZonedDateTime
to java.util.Date
, do
Date date = Date.from(zonedDateTime.toInstant());
这篇关于如何将Joda LocalDate转换为java.util.Date?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!