Johan Wikström
Johan Wikström

Reputation: 4239

How do I convert a org.joda.time.LocalDateTime into java.Util.Calendar?

The question is in the heading really. What is the simplest way to do this?

Upvotes: 3

Views: 4611

Answers (3)

javaMaster
javaMaster

Reputation: 316

Maybe you can try this approach, LocalDateTime to Calendar of java.util:

Conversion sequence: LocalDateTime -> DateTime -> Calendar

    LocalDateTime ldt = new LocalDateTime();
    DateTime dt = ldt.toDateTime();
    Calendar c = dt.toCalendar(null);
    System.out.println(c.getTime());

Hope this one works for you. Cheers!

Upvotes: 1

mats.nowak
mats.nowak

Reputation: 329

LocalDateTime jodaTime = LocalDateTime.now();
Calendar cal = Calendar.getInstance();
cal.setTime(jodaTime.toDate());

Upvotes: 4

Paul John
Paul John

Reputation: 1661

You can use toCalendar

http://joda-time.sourceforge.net/api-release/org/joda/time/base/AbstractDateTime.html#toCalendar%28java.util.Locale%29

Here is a post Approach to convert from org.joda.time.DateTime to java.util.Calendar

eg.

Date date = dateTime.toDate();
 Calendar calendar = dateTime.toCalendar(Locale.getDefault());

Upvotes: 1

Related Questions