File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Node.js in Action
this week in the
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 Java. Assuming you are using
objects, the disscussion in those articles apply since the
class extends the
I agree. Here's the link:
subject: Get timestamp difference in hours and minutes
Comparing Timestamp values?
how to compare time row by row
To calculate Time diffrence
Timestamp in GMT and the difference
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014