Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42828

Get java.util.Date out from Joda-Time DateTime

I have code like this:

// old_api(Date date)
old_api(calendar.getTime());

Currently, I need to replace Calendar with Joda-Time DateTime. I was wondering how I can get java.util.Date out from Joda-Time DateTime?

Upvotes: 47

Views: 36314

Answers (2)

Shailesh
Shailesh

Reputation: 388

One way to do that is: Extract milli-seconds from joda-datetime instance and then pass it to java.util.Date constructor.

Date date = new java.util.Date(jodaDateTime.getMillis())

Upvotes: 0

BalusC
BalusC

Reputation: 1109570

Use DateTime#toDate().

Date date = dateTime.toDate();

Upvotes: 96

Related Questions