Solved

subtracting time

Posted on 2004-08-31
3
726 Views
Last Modified: 2008-03-17
I have time that i read from a file.
The time is of the format hh:mm:ssssss
now i have to subtract the one time from other.
is there a special class for doing it or any special way of doing it ?

thanks.

iCe b
0
Comment
Question by:iceb
3 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 450 total points
ID: 11947601
That depends on your implementation. By example in Visual C++ you have the CTime and CTimeSpan class.
A portable way is to use the struct tm;

struct tm aTime;
aTime.tm_hour = 5;
aTime.tm_min = 15;
aTime.tm_sec = 43;
// etcetera

now to convert to a unique value use mktime()

time_t time;   // one unique integer to express time, know as Unix-Time
time = mktime(aTime);

if you have another time_t value, you can substract one for the other, result is expresed in seconds

Read more at:
http://msdn.microsoft.com/library/en-us/vclib/html/_crt_time_management.asp
0
 
LVL 3

Assisted Solution

by:kumvjuec
kumvjuec earned 50 total points
ID: 11965861
If the time is all you have, then the best way is to convert both the times into seconds and then convert them back again.
If you are using c++ then use atol to convert from string to long. This is required because if would be easier to read directly the line from the file as string.

What language are you using btw??
0
 
LVL 1

Author Comment

by:iceb
ID: 12002601
i am using vc++ 6.0.
program is scre*ed up.
please gimme some time to respond.

thx for the replies.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Would like to move button in a function 3 83
thread-safe code in c++ 2 120
Create a path if not exists 7 105
C++ :Change value from  DisableCMD registry 4 69
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question