1

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();
Jedi Knight
  • 571
  • 2
  • 7
  • 18

3 Answers3

8
Date da = loct.toDateTimeToday().toDate();  
Ilya
  • 27,538
  • 18
  • 104
  • 148
  • And don't forget to decide which timezone you want to use, otherwise you could have a lot of fun ocasionally during DST dates. This expression uses JVM default tz. – kan Mar 21 '13 at 09:19
  • @kan or specific TZ, setted by `DateTimeZone#setDefault(DateTimeZone)` – Ilya Mar 21 '13 at 09:31
1

Have you tried

locd.withFields(loct).toDate();
NilsH
  • 13,119
  • 4
  • 38
  • 57
0

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.

Kumar Shorav
  • 529
  • 4
  • 16