Forums Register Login

accurate time difference betwwen two time stamp

+Pie Number of slices to send: Send
how i can i calculate time difference between two time stamp like 21-08-2013 10:00:00 am and 22-08-2013 2:00:00 pm. i want accurate difference of days,hour, minute and second in java.
1
+Pie Number of slices to send: Send
In pseudo code
1) Use SimpleDateFormat to obtain the Date objects
2) Obtain the long long value from the date object
3) 1 second = 1000 ms. 1 minute = 60 seconds. 1 hour = 60 minutes. 1 day = 24 hours.
4) Use #3 to compute the difference.
1
+Pie Number of slices to send: Send
Or you could replace steps 3 and 4 by something from the Joda Time library, which makes calculations such as this one fairly easy and readable.
1
+Pie Number of slices to send: Send
 

Jan Hoppmann wrote:Or you could replace steps 3 and 4 by something from the Joda Time library, which makes calculations such as this one fairly easy and readable.


@viral: While I totally agree with Jan's suggestion, the fact is that (at least as far as I've heard) version 8 of Java is going to include a new Date/Time API, based on - but not identical to - Joda Time.

My suspicion is that they will have a lot in common, so learning Joda Time will probably give you a good head start, but if you're going to be using dates and times heavily, you might want to wait until version 8 is out (March 2014); or at least familiarise yourself with the likely changes (see the JSR-310 page), so that you can design your API to change to version 8 with the minimum of fuss.

HIH

Winston
+Pie Number of slices to send: Send
can you provide me code in details with example. Thanks in Advance.
+Pie Number of slices to send: Send
 

viral thakar wrote:can you provide me code in details with example. Thanks in Advance.


Sorry. The Ranch is NotACodeMill
Tell us what you have tried, where you are stuck, post your SSCCE and we will help point you in the right direction.
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 694 times.
Similar Threads
back ground process id ??
Format lengthy date zone ids to their respective short zone suffixes
String to time stamp
Millisecond accuracy
Adding offset to time zone in java
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:22:02.