please help me compute for the time..

i have extracted different time values from a database, i stored it in a String since i don't know which data type to use. this values came from a DataList in a variable named jamTime..
then i extracted the time using:

String startTime = jamTime.getString("start_date_time");
String endTime = jamTime.getString("end_date_time");

i want to get the difference between this two time. the value of these variables were:
startTime = "02:33:45"
endTime = "02:36:56"

and i need to display their difference in seconds.

please help me how to compute for this if there is such format or parsing method to convert my string into a value which can be manipulated with arithmetic functions.

thanks... feel free to ask me questions if i did not explain it quite well...

first of all, you must understand that the String class is not meant to compute things with. If you really want to compare dates, you might want to check out the classes
'Date', or, propably even better: 'GregorianCalendar'. By using those, it should be no real problem determining the difference between the two.

Since 'Date' has got a number of deprecated methods, I'd advice you to use GregorianCalendar

or, you could also use this String objects, seperate them in substrings, convert these to integers and use those to calculate the difference, but I think comparing dates is still a better choice than to compare numbers.

to convert a string to an real number which you will need with your conversions use double num = Double.parseDouble(enteredString);

This article has been dead for over six months. Start a new discussion instead.