Current Time: General Purpose Classes
The following procedure shows how to create a CTime object and initialize it with the current time.
To get the current time
Allocate a CTime object, as follows:
CTime theTime;
Note Uninitialized CTime objects are not initialized to a valid time.
Call the CTime::GetCurrentTime function to get the current time from the operating system. This function returns a CTime object that can be used to set the value of CTime, as follows:
theTime = CTime::GetCurrentTime();
Since GetCurrentTime is a static member function from the CTime class, you must qualify its name with the name of the class and the scope resolution operator (::),
CTime::GetCurrentTime()
.
Of course, the two steps outlined previously could be combined into a single program statement as follows:
CTime theTime = CTime::GetCurrentTime();