User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 423,540 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,128 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 362 | Replies: 2
Reply
Join Date: Jan 2008
Posts: 13
Reputation: wolverine_ramir is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
wolverine_ramir wolverine_ramir is offline Offline
Newbie Poster

how do i compute for the time??

  #1  
Feb 19th, 2008
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...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 181
Reputation: stultuske is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
stultuske's Avatar
stultuske stultuske is offline Offline
Junior Poster

Re: how do i compute for the time??

  #2  
Feb 20th, 2008
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.
Reply With Quote  
Join Date: Jul 2007
Posts: 53
Reputation: piers is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
piers piers is offline Offline
Junior Poster in Training

Re: how do i compute for the time??

  #3  
Feb 21st, 2008
to convert a string to an real number which you will need with your conversions use double num = Double.parseDouble(enteredString);
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 5:43 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC