How to sum 2 joda-time DateTime values ​​(one contains date and zero time, and the other contains time and zero date)?

In my Scala 2.8 program, I use joda time with its scala -time shell. I have 2 DateTime values, one for the date (with zero time fields) and one for the time (with zero fields) (the reason for the separation is the storage architecture).

How do I get a different DateTime value with setting the date and time from a pair of sources?

+3
source share
1 answer

You must use LocalDatefor date and LocalTimefor time. These are the appropriate types for dates and times, respectively. You can get each one DateTimewith DateTime.toLocalDate()and DateTime.toLocalTime()if you need to use them as values DateTimeto get you started. Ideally, you would not have built DateTimeat all until you had two bits separately :)

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

+10
source

Source: https://habr.com/ru/post/1763905/


All Articles