我想将Joda LocalTime转换为java.util.Date并将转换为 LocalDate。如果这有帮助,我已经有了一个LocalTime对象。显然,LocalTime中没有“日期”部分。所以我不能直接将LocalTime转换为Date。有一种简单的方法可以做到这一点吗?
步骤 -
LocalTime loct
LocalDate locd = Todays date + loct
Date da = locd.toDate();
答案 0 :(得分:8)
Date da = loct.toDateTimeToday().toDate();
答案 1 :(得分:1)
你试过吗
locd.withFields(loct).toDate();
答案 2 :(得分:0)
你也可以使用它 -
Date dtUtil = DateTime.now(DateTimeZone.getDefault()).toDate();
通用方式是 -
Date dtUtil = DateTime.now(DateTimeZone.forID("TimeZoneString")).toDate();
其中“TimeZoneString”是您想要获得时间的timeZone id。
DateTimeZone.getDefault()将返回系统的本地区域。