Solved

subtracting time

Posted on 2004-08-31
3
728 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

624 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