The moose likes JSP and the fly likes Final date question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Final date question" Watch "Final date question" New topic
Author

Final date question

Dave Foley
Greenhorn

Joined: Feb 25, 2003
Posts: 9
I'm trying to compare two datetime values and get the difference between them in seconds. I can't find anything about it on the sun site.
Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
You can use the Date's getTime() function to return the two dates as milliseconds and then divide by 1000 to get seconds.
Date dt1 = new Date();
Date dt2 = new Date();
long l1 = dt1.getTime();
long l2 = dt2.getTime();
long dttmDiffInSecs = (l2 - l1) / 1000;
Brian
Dave Foley
Greenhorn

Joined: Feb 25, 2003
Posts: 9
Thanks again for the help.
 
 
subject: Final date question
 
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com