Elapsed Time: General-Purpose Classes

OverviewHow Do I

The following procedure shows how to calculate the difference between two CTime objects and get a CTimeSpan result.

To calculate elapsed time

  • Use the CTime and CTimeSpan objects to calculate the elapsed time, as follows:

    CTime startTime = CTime::GetCurrentTime();
    
    // ... perform time-consuming task ...
    
    CTime endTime = CTime::GetCurrentTime();
    
    CTimeSpan elapsedTime = endTime - startTime;
    

    Once you have calculated elapsedTime, you can use the member functions of CTimeSpan to extract the components of the elapsed-time value.