[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1116
  • Last Modified:

time in seconds since 1980?

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
dgraf
Asked:
dgraf
1 Solution
 
wpintoCommented:
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
 
dgrafAuthor Commented:
Excellent, it works perfectly!

Thanks
Dani
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now