time calculation help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 12
Reputation: rajsharma_85 is an unknown quantity at this point 
Solved Threads: 0
rajsharma_85 rajsharma_85 is offline Offline
Newbie Poster

time calculation help

 
0
  #1
Nov 20th, 2007
hi guys,

I am making a program in which I have to enter start date and time and stop date and time in format like 01:05:07 15:26:57

I know that i need to use <time.h> function for that but i don't know how can i calculate the difference between time. i have no clue of that. could you guys give me some tips on that?
Last edited by rajsharma_85; Nov 20th, 2007 at 11:17 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 32
Reputation: dmmckelv is an unknown quantity at this point 
Solved Threads: 0
dmmckelv dmmckelv is offline Offline
Light Poster

Re: time calculation help

 
0
  #2
Nov 20th, 2007
This may not be the best way to do it but, you could build a function to convert the times into seconds and use subtraction. Your function would have to tokenize the time format using the : as a break.

Actually, you don't even need to convert the times into seconds. Just tokenize the time into hours and minutes then subtract. Your output will already be in the correct format.
Mark
Last edited by dmmckelv; Nov 20th, 2007 at 11:30 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 12
Reputation: rajsharma_85 is an unknown quantity at this point 
Solved Threads: 0
rajsharma_85 rajsharma_85 is offline Offline
Newbie Poster

Re: time calculation help

 
0
  #3
Nov 20th, 2007
but i am already taking input from the user in hours minutes and seconds in hh:mm:ss format. but i don't know how to calculate the difference between two different inputs. i don't know that particular equation

do you mean to say (hh:mm:ss)-(hh:mm:ss) ?
Last edited by rajsharma_85; Nov 20th, 2007 at 11:41 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 32
Reputation: dmmckelv is an unknown quantity at this point 
Solved Threads: 0
dmmckelv dmmckelv is offline Offline
Light Poster

Re: time calculation help

 
0
  #4
Nov 20th, 2007
Sure, use a tokenizer to separate HH, MM, and SS from HH:MMS. Then subtract HH from your other HH, MM from MM, etc. As long as it is in 24hr format it should work. You will have to write some code to decrement HH and MM if you need to borrow. Once you have done the math, put the answer back into a string in the format of HH:MMS or whatever other format you need.

Mark

I don't know what the deal is with the smileys but I mean ": S" minus the space." Stupid smileys.
Last edited by dmmckelv; Nov 20th, 2007 at 11:46 am. Reason: Stupid Smileys
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 12
Reputation: rajsharma_85 is an unknown quantity at this point 
Solved Threads: 0
rajsharma_85 rajsharma_85 is offline Offline
Newbie Poster

Re: time calculation help

 
0
  #5
Nov 20th, 2007
okay. so you are trying so say to use (hh1-hh2) and (mm1-mm2) and (ss1-ss2) format?
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 32
Reputation: dmmckelv is an unknown quantity at this point 
Solved Threads: 0
dmmckelv dmmckelv is offline Offline
Light Poster

Re: time calculation help

 
0
  #6
Nov 20th, 2007
yep! well HH(Stop)-HH(Start), etc..
Last edited by dmmckelv; Nov 20th, 2007 at 11:49 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 12
Reputation: rajsharma_85 is an unknown quantity at this point 
Solved Threads: 0
rajsharma_85 rajsharma_85 is offline Offline
Newbie Poster

Re: time calculation help

 
0
  #7
Nov 20th, 2007
thanks for your help dmmclev.

can i ask you one more question? what should i do if i want to refresh that time every second?

for example, i am my program is recording a channel between start and stop time and i want to show the amount of time that has been recorded and make it refreshing every second.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: time calculation help

 
0
  #8
Nov 20th, 2007
Each second add 1 to a counter and output that counter.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: time calculation help

 
0
  #9
Nov 20th, 2007
<vader>
I sense a disturbance in the ethernet, a sense that the same question has been asked elsewhere
</vader>
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 12
Reputation: rajsharma_85 is an unknown quantity at this point 
Solved Threads: 0
rajsharma_85 rajsharma_85 is offline Offline
Newbie Poster

Re: time calculation help

 
0
  #10
Nov 26th, 2007
sorry man, i didn't know the rules. i posted it elsewhere because i didn't know which forum is faster in replying and i was really in hurry to get the help
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC