Joda Time: Find the amount of time between two dates
Posted by Chad | Posted in Groovy, Java | Posted on 04-03-2010
0
Joda Time is a Date/Time API proposed for Java SE 7. Below, I have a Groovy script that uses the 1.6 Joda Time library to find the difference between two dates.
import org.joda.time.*
...
def i = new Interval(startDate.getTime(),endDate.getTime())
def p = i.toPeriod()
println "Time Difference: " + p.getSeconds() + "." + p.getMillis() + " Seconds"
In addition to Seconds and Milliseconds, you can get the number of Days, Hours, Minutes, Months, Weeks, and Years.
