Using Groovy (or Java) how can I convert a org.joda.time.LocalDateTime
to a java.util.Date
?
import org.joda.time.*
Calendar cal = Calendar.instance
cal.set(Calendar.DATE, 1)
cal.set(Calendar.HOUR, 0)
cal.set(Calendar.MINUTE, 0)
cal.set(Calendar.SECOND, 0)
cal.set(Calendar.MILLISECOND, 0)
Date startOfTheMonth = cal.time
LocalDateTime localDateTime = new LocalDateTime()
localDateTime = localDateTime.withDayOfMonth(1)
localDateTime = localDateTime.withTime(0,0,0,0)
localDateTime.minusMonths(6)
Date dateFromLocalDate = localDateTime.toDateTime().toDate()
println startOfTheMonth
println dateFromLocalDate
assert startOfTheMonth.equals(dateFromLocalDate)
using localDateTime.toDateTime().toDate()
gives me a java.util.Date
that is 6 hours off I m in Central Standard time (GMT +6)
How do I convert my LocalDateTime
date back to a java.util.Date
such that the time matches?