943,740 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4245
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Nov 20th, 2007
0

time calculation help

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rajsharma_85 is offline Offline
14 posts
since Nov 2007
Nov 20th, 2007
0

Re: time calculation help

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
dmmckelv is offline Offline
33 posts
since Nov 2006
Nov 20th, 2007
0

Re: time calculation help

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rajsharma_85 is offline Offline
14 posts
since Nov 2007
Nov 20th, 2007
0

Re: time calculation help

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
Reputation Points: 10
Solved Threads: 0
Light Poster
dmmckelv is offline Offline
33 posts
since Nov 2006
Nov 20th, 2007
0

Re: time calculation help

okay. so you are trying so say to use (hh1-hh2) and (mm1-mm2) and (ss1-ss2) format?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rajsharma_85 is offline Offline
14 posts
since Nov 2007
Nov 20th, 2007
0

Re: time calculation help

yep! well HH(Stop)-HH(Start), etc..
Last edited by dmmckelv; Nov 20th, 2007 at 11:49 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
dmmckelv is offline Offline
33 posts
since Nov 2006
Nov 20th, 2007
0

Re: time calculation help

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rajsharma_85 is offline Offline
14 posts
since Nov 2007
Nov 20th, 2007
0

Re: time calculation help

Each second add 1 to a counter and output that counter.
Moderator
Reputation Points: 3278
Solved Threads: 891
Posting Sage
WaltP is offline Offline
7,718 posts
since May 2006
Nov 20th, 2007
0

Re: time calculation help

<vader>
I sense a disturbance in the ethernet, a sense that the same question has been asked elsewhere
</vader>
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Nov 26th, 2007
0

Re: time calculation help

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rajsharma_85 is offline Offline
14 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Regex - problem seemed to be easy...
Next Thread in C++ Forum Timeline: Compilation error in graphml.cpp





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC