Solved

time in seconds since 1980?

Posted on 1997-11-30
2
1,067 Views
Last Modified: 2008-03-17
I have to write a function which evaluates
from the system time a number of seconds.
This number of seconds must represent the
number of seconds since 1/1/1980 til the mentioned
system time.
The number of seconds should be an integer (or
long integer) value.

I work with Visual C++ (4.0 & 5.0).
Does already such a function exist?

Thanks
Dani
0
Comment
Question by:dgraf
2 Comments
 
LVL 2

Accepted Solution

by:
wpinto earned 50 total points
ID: 1174407
Hi Dani,

There is no simple function which will do the job for you. But the result could be easily achieved using the CTime & CTimeSpan classes of MFC

The following piece of code will give you the required results

  CTime t = CTime::GetCurrentTime();
  CTimeSpan ts = t - CTime(1980, 1, 1);
  long lNoOfSeconds = ts.GetTotalSeconds();

The total no of seconds from 1/1/1980 till the current time is available in the long variable lNoOfSeconds.

Hope this helps

Wilfred
0
 

Author Comment

by:dgraf
ID: 1174408
Excellent, it works perfectly!

Thanks
Dani
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

810 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