Share via


CTime::operator +, -

These operators add and subtract CTimeSpan and CTime objects.

CTime operator +( 
   CTimeSpan timeSpan  
) const throw( ); 
CTime operator -( 
   CTimeSpan timeSpan  
) const throw( ); 
CTimeSpan operator -( 
   CTime time  
) const throw( );

Parameters

  • timeSpan
    The CTimeSpan object to be added or subtracted.

  • time
    The CTime object to be subtracted.

Return Value

A CTime or CTimeSpan object representing the result of the operation.

Remarks

CTime objects represent absolute time, CTimeSpan objects represent relative time. The first two operators allow you to add and subtract CTimeSpan objects to and from CTime objects. The third operator allows you to subtract one CTime object from another to yield a CTimeSpan object.

Example

CTime t1(1999, 3, 19, 22, 15, 0); // 10:15 PM March 19, 1999
CTime t2(1999, 3, 20, 22, 15, 0); // 10:15 PM March 20, 1999
CTimeSpan ts = t2 - t1;             // Subtract 2 CTimes
ATLASSERT(ts.GetTotalSeconds() == 86400L);
ATLASSERT((t1 + ts) == t2);       // Add a CTimeSpan to a CTime.
ATLASSERT((t2 - ts) == t1);       // Subtract a CTimeSpan from a CTime.   

Requirements

Header: atltime.h

See Also

Reference

CTime Class

Hierarchy Chart

Other Resources

CTime Members