c++mfcctime

MFC C++, adding seconds (int) to a current CTime variable


noob to C++. I have a CTime (actually it's a CTimeEx) object. The value of the time value is:

CExTime now = now.GetSystemTime();

I am receiving an int, such as 60, to add to that time; this means that if I have 12:01:30 , then I'd want 12:02:30.

How can I add the int to the CTime? Would this work?

currBERecored.m_BeUpdateTime = now + secondsFromFile;

Solution

  • You can add via the + operator a CTimeSpan to a CTime object. The CTimeSpan is the correct class to represent a time interval, you can construct a CTimeSpan of a certain number of seconds by using this constructor:

    CTimeSpan(
       __time64_t time 
    ) throw( ); 
    

    in which time is the desired amount of seconds.