Condividi tramite


CTime::Format

Call this member function to create a formatted representation of the date-time value.

CString Format(
   LPCTSTR pszFormat 
) const;
CString Format(
   UINT nFormatID 
) const;

Parameters

  • pszFormat
    A formatting string similar to the printf formatting string. Formatting codes, preceded by a percent (%) sign, are replaced by the corresponding CTime component. Other characters in the formatting string are copied unchanged to the returned string. See the run-time function strftime for a list of formatting codes.

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

Return Value

A CString that contains the formatted time.

Remarks

If the status of this CTime object is null, the return value is an empty string.

This method throws an exception if the date-time value to format does not range from midnight, January 1, 1970 through December 31, 3000 Universal Coordinated Time (UTC).

Example

CTime t(1999, 3, 19, 22, 15, 0); 
// 10:15 PM March 19, 1999
CString s = t.Format(_T("%A, %B %d, %Y"));
ATLASSERT(s == _T("Friday, March 19, 1999"));   

Requirements

Header: atltime.h

See Also

Reference

CTime Class

Hierarchy Chart

CTime::FormatGmt

Other Resources

CTime Members