Compartilhar via


COleDateTimeSpan::Format

Generates a formatted string representation of a COleDateTimeSpan object.

CString Format( 
   LPCTSTR pFormat  
) const; 
CString Format( 
   UINT nID  
) const;

Parameters

  • pFormat
    A formatting string similar to the printf formatting string. Formatting codes, preceded by a percent (%) sign, are replaced by the corresponding COleDateTimeSpan component. Other characters in the formatting string are copied unchanged to the returned string. The value and meaning of the formatting codes for Format are listed below:

    • %H   Hours in the current day

    • %M   Minutes in the current hour

    • %S   Seconds in the current minute

    • %%   Percent sign

    The four format codes listed above are the only codes that Format will accept.

  • nID
    The resource ID for the format-control string.

Return Value

A CString that contains the formatted date/time-span value.

Remarks

Call these functions to create a formatted representation of the time-span value. If the status of this COleDateTimeSpan object is null, the return value is an empty string. If the status is invalid, the return string is specified by the string resource IDS_INVALID_DATETIMESPAN.

A brief description of the forms for this function follows:

  • Format( pFormat )
    This form formats the value using the format string that contains special formatting codes that are preceded by a percent sign (%), as in printf. The formatting string is passed as a parameter to the function.

  • Format( nID )
    This form formats the value using the format string that contains special formatting codes that are preceded by a percent sign (%), as in printf. The formatting string is a resource. The ID of this string resource is passed as the parameter.

Example

// get the current time
COleDateTime tmStart = COleDateTime::GetCurrentTime();

// waste some time
CString str;
::Sleep(3000);

// get the current time again
COleDateTime tmFinish = COleDateTime::GetCurrentTime();

// find the difference
COleDateTimeSpan tmSpan = tmFinish - tmStart;

// tell the user
str = tmSpan.Format(_T("%S seconds elapsed"));
_tprintf_s(_T("%s\n"), (LPCTSTR) str);

Requirements

Header: atlcomtime.h

See Also

Reference

COleDateTimeSpan Class

Hierarchy Chart

COleDateTimeSpan::GetStatus