Condividi tramite


CTimeSpan::Format

Generates a formatted string that corresponds to this CTimeSpan.

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

Parameters

  • pFormat, pszFormat
    A formatting string similar to the printf formatting string. Formatting codes, preceded by a percent (%) sign, are replaced by the corresponding CTimeSpan 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:

    • %D   Total days in this CTimeSpan

    • %H   Hours in the current day

    • %M   Minutes in the current hour

    • %S   Seconds in the current minute

    • %%   Percent sign

  • nID
    The ID of the string that identifies this format.

Return Value

A CString object that contains the formatted time.

Remarks

The Debug version of the library checks the formatting codes and asserts if the code is not in the list above.

Example

CTimeSpan ts(3, 1, 5, 12); // 3 days, 1 hour, 5 min, and 12 sec
CString s = ts.Format(_T("Total days: %D, hours: %H, mins: %M, secs: %S"));
ATLASSERT(s == _T("Total days: 3, hours: 01, mins: 05, secs: 12"));   

Requirements

Header: atltime.h

See Also

Reference

CTimeSpan Class

Hierarchy Chart

Other Resources

CTimeSpan Members