File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Get timestamp difference in hours and minutes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Get timestamp difference in hours and minutes" Watch "Get timestamp difference in hours and minutes" New topic

Get timestamp difference in hours and minutes

dianna goldfarb

Joined: May 12, 2008
Posts: 2

I have 2 Timestamp objects that I want to calculate the difference in minutes and seconds.

Timestamps are in the form of '2009-06-29 10:38:02.128459'

There is a TimeStamp class that have a difference method, but I am not sure how to use this.

Thank you!

Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 272

The Timestamp class(es) have nothing to do with what you want to do, You need to use the Date and DateFormat classes.

Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

You can take a look at these JavaWorld articles: Calculating Java dates and Working in Java time : Learn the basics of calculating elapsed time in Java - they do a nice job of explaining Date math in Java. Assuming you are using java.sql.Timestamp objects, the disscussion in those articles apply since the java.sql.Timestamp class extends the java.util.Date class.
I agree. Here's the link:
subject: Get timestamp difference in hours and minutes
Similar Threads
To calculate Time diffrence
Timestamp in GMT and the difference
Comparing Timestamp values?
how to compare time row by row