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.

Share:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • FriendFeed
  • Ping.fm
  • StumbleUpon
  • Technorati

Write a comment

What is 6 + 5 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)