File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes subtract/add date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "subtract/add date" Watch "subtract/add date" New topic
Author

subtract/add date

Nijeesh Balan
Ranch Hand

Joined: Oct 09, 2000
Posts: 116
Hi,
I just want to measure the time taken for the completion of process to the finest millisecond possible.
Say,
Start time,
End time.
Time difference..
If it is run as a batch process, then the time difference will be accumulated and be printed at the end.
Which is the best method to implement this?
Please reply ASAP
Thanks & Regards,
Nijeesh.


Thanks & Regards,<br />Nijeesh.
David Duran
Ranch Hand

Joined: Feb 11, 2002
Posts: 122
Is this is what you are asking:
1. Get start time
2. Start process
3. End process
4. Get end time
5. Calculate time between start & end
6. Repeat
7. Print out time difference when done


Is this what you were asking?
[ November 26, 2002: Message edited by: David Duran ]
Nijeesh Balan
Ranch Hand

Joined: Oct 09, 2000
Posts: 116
Hi David,
This is what I was looking for except for the fact the difference is being returned in milliseconds. Do I have to divide and multiply to get it converted into hours/seconds/minutes.. or is it possible to do the same with some format specifier?
Thanks for your reply..
Regards,
Nijeesh.
David Duran
Ranch Hand

Joined: Feb 11, 2002
Posts: 122
Nijeesh,
I would say just divide. I don't know of a format specifier off of the top of my head.
You can refer to this article and grab his code to convert to the larger time units:
http://www.javaworld.com/javaworld/jw-03-2001/jw-0330-time-p2.html
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Hi - If you use the long (timeDifference) in the above code like:
Date d = new Date(timeDifference);
then d will be some number of months, days, hours, minutes, seconds, .... since Jan 1, 1970. Ignore the year, and just look at the other fields for the elapsed time.
Alternatively, there is an open source implementation of ISO8601 dates being done on sourceforge (the Joda project). Date arithmetic is reasonably straight forward. You might take a look at that.
HTH, Guy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: subtract/add date