• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DateDiff Function in Java?

 
Sonny Wong
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know that the Java API has a simple method to find out the time difference between two Gregorian Date objects in date?
 
John Fairbairn
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To compute the difference between two dates, I usually convert the dates to java.util.Date objects, call their getTime() methods, and subtract.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by J Fairbairn:
To compute the difference between two dates, I usually convert the dates to java.util.Date objects, call their getTime() methods, and subtract.

You could just use the Calendar's getTimeInMillis() method. That method returns a long.
 
Sonny Wong
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the getTimeInMillis method and is working. Thanks guys!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic