Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get timestamp difference in hours and minutes

 
dianna goldfarb
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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!

-dianna
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic