This week's book giveaway is in the Jobs Discussion forum. We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line! See this thread for details.

You can parse time and date strings with java.text.SimpleDateFormat. What you want to do is add two time intervals, I think, since adding two times doesn't make that much sense (what is Oct 31 + Dec 25?) Some things to watch out for:

1. Set your date format's time zone to UTC, since you don't want to rassle with time zones.

2. I would extact the long time value from the parsed date and work with that. For instance you can add two of them together to add the two intervals. While you could turn around and use the date format to format the result as a string, like "05:00:10 + 01:35:05 = 06:35:15", watch out if the hours exceed 24 -- it will want to take you from 1 Jan 1970 to 2 Jan 1970! It's simple to format the time interval manually:

Originally posted by Steven Smith: How do I add 2 time stamps in hh:mm:ss format? For example: 05:00:10 + 01:35:05

Like Jeff said, adding two times doesn't mean a whole lot of sense. Does the second timestamp represent a time interval, i.e, does the example expression mean 1 hr 35 mins and 5 seconds after 5:00:10 am/pm? [ December 13, 2005: Message edited by: Junilu Lacar ]

Like Jeff said, adding two times doesn't mean a whole lot of sense.

Sorry, I just realized I shouldn't have wrote "time stamp." I think what I'm asking is much simpler. If driving my car from point A to point B takes 5 hours and 10 seconds (05:00:10) and driving from point B to point C takes 1 hour, 35 minutes and 5 seconds (01:35:05), I want to add the two times together (point A to C = 06:35:15) with everything in hh:mm:ss format. Also, if it took 25 hours to go from point A to point B, I would end up with 26:35:05, not a clock time. The two times would be string values already provided (in hh:mm:ss) but I need to add them together. [ December 13, 2005: Message edited by: Steven Smith ]

Could you convert each time to seconds, add them together and then convert back to hours, minutes and seconds?

If you have 10.000 seconds, how many times does 3600 go into 10.000? The answer is 2, i.e. 2 hours. Use modulus to get the remaining seconds, i.e. 2800 seconds.

Next up is minutes: how many times does 60 go into 2800? The answer is 46, so you have 2 hours, 46 minutes. Next, use modulus to find the remainder, which is 40 seconds.

I think my thinking here is correct...

[ December 13, 2005: Message edited by: Flo Powers ]