Ivan
Ivan

Reputation: 64227

How to sum 2 joda-time DateTime values (one containing a date and a zero time and another containing a time and a zero date)?

In a Scala 2.8 program of mine I use joda-time with its scala-time wrapper. I've got 2 DateTime values, one for a date (with zero time fields) and one for time (with zero date fields) (the reason of separation is a storage architecture).

How do I get another DateTime value with both date and time parts set from a source pair?

Upvotes: 3

Views: 1095

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502036

You should be using LocalDate for the date and LocalTime for the time. Those are the appropriate types for dates and times respectively. You can get each from a DateTime with DateTime.toLocalDate() and DateTime.toLocalTime() if you have to have them as DateTime values to start with. Ideally you wouldn't build a DateTime at all until you've got both bits separately though :)

Then you can LocalDate.toDateTime(LocalTime, DateTimeZone).

Upvotes: 10

Related Questions