954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how do i compute for the time??

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...

wolverine_ramir
Newbie Poster
18 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

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.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

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

piers
Junior Poster in Training
68 posts since Jul 2007
Reputation Points: 10
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You