| | |
time calculation help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 12
Reputation:
Solved Threads: 0
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?
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.
•
•
Join Date: Nov 2006
Posts: 32
Reputation:
Solved Threads: 0
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
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.
•
•
Join Date: Nov 2007
Posts: 12
Reputation:
Solved Threads: 0
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) ?
do you mean to say (hh:mm:ss)-(hh:mm:ss) ?
Last edited by rajsharma_85; Nov 20th, 2007 at 11:41 am.
•
•
Join Date: Nov 2006
Posts: 32
Reputation:
Solved Threads: 0
Sure, use a tokenizer to separate HH, MM, and SS from HH:MM
S. 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:MM
S 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.
S. 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:MM
S 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
•
•
Join Date: Nov 2007
Posts: 12
Reputation:
Solved Threads: 0
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.
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.
<vader>
I sense a disturbance in the ethernet, a sense that the same question has been asked elsewhere
</vader>
I sense a disturbance in the ethernet, a sense that the same question has been asked elsewhere
</vader>
![]() |
Similar Threads
- request for java code to set the system time zone (Java)
- Sleep method nad System time (C++)
- Aquarium Program- Help setting system time etc... (C++)
- Display System Time in VC++.net (Game Development)
- system time reset detection (C)
- inputing system("date /t") and system("time /t") into a file (C++)
- Setting system date and time using c++ (C++)
Other Threads in the C++ Forum
- Previous Thread: Regex - problem seemed to be easy...
- Next Thread: Compilation error in graphml.cpp
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






