Solved

subtracting time

Posted on 2004-08-31
3
724 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

777 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