How to convert Joda time LocalTime to java.util.Date?

蓝咒 提交于 2019-12-06 13:44:05

问题


I want to convert Joda LocalTime to java.util.Date and not LocalDate. If this helps, I already have a LocalTime object with me. Obviously, there is no "date" part in LocalTime. So I cannot convert LocalTime to Date directly. Is there a simple way to do this ?

Steps -

LocalTime loct 
LocalDate locd = Todays date + loct
Date da = locd.toDate();

回答1:


Date da = loct.toDateTimeToday().toDate();  



回答2:


Have you tried

locd.withFields(loct).toDate();



回答3:


You can also use this--

Date dtUtil = DateTime.now(DateTimeZone.getDefault()).toDate();

the generic way is -

Date dtUtil = DateTime.now(DateTimeZone.forID("TimeZoneString")).toDate();

where "TimeZoneString"is timeZone id for which you want to get the time.

DateTimeZone.getDefault() will return the local zone of the system.



来源:https://stackoverflow.com/questions/15543031/how-to-convert-joda-time-localtime-to-java-util-date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!