A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Get timestamp difference in hours and minutes
Joined: May 12, 2008
Jun 29, 2009 12:12:21
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.
Joined: Jun 17, 2009
Jun 29, 2009 13:39:10
The Timestamp class(es) have nothing to do with what you want to do, You need to use the Date and
String date1 = "...", date2 = "..."; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); Date d1 = df.parse(date1); Date d2 = df.parse(date2); long diffInMilliseconds = Math.abs(d1.getTime() - d2.getTime());
SCJP 6 || SCWCD 5
Joined: Dec 17, 2003
Jun 29, 2009 14:06:47
You can take a look at these JavaWorld articles:
Calculating Java dates
Working in Java time : Learn the basics of calculating elapsed time in Java
- they do a nice job of explaining Date math in
. Assuming you are using
objects, the disscussion in those articles apply since the
class extends the
Have you checked out
subject: Get timestamp difference in hours and minutes
Timestamp in GMT and the difference
To calculate Time diffrence
how to compare time row by row
Comparing Timestamp values?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015