本文介绍了如何将Joda LocalDate转换为java.util.Date?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

转换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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 01:48