COleDateTime::Format

Creates a formatted representation of the date/time value.

CString Format(
   DWORD dwFlags = 0,
   LCID lcid = LANG_USER_DEFAULT
) const;
CString Format(
   LPCTSTR lpszFormat 
) const;
CString Format(
   UINT nFormatID 
) const;

Parameters

  • dwFlags
    Indicates one of the following locale flags:

    • LOCALE_NOUSEROVERRIDE   Use the system default locale settings, instead of custom user settings.

    • VAR_TIMEVALUEONLY   Ignore the date portion during parsing.

    • VAR_DATEVALUEONLY   Ignore the time portion during parsing.

  • lcid
    Indicates locale ID to use for the conversion. For more information about language identifiers, see Language Identifiers.

  • lpszFormat
    A formatting string similar to the printf formatting string. Each formatting code, preceded by a percent (%) sign, is replaced by the corresponding COleDateTime component. Other characters in the formatting string are copied unchanged to the returned string. See the run-time function strftime for more information. The value and meaning of the formatting codes for Format are:

    • %H   Hours in the current day

    • %M   Minutes in the current hour

    • %S   Seconds in the current minute

    • %%   Percent sign

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

Return Value

A CString that contains the formatted date/time value.

Remarks

If the status of this COleDateTime object is null, the return value is an empty string. If the status is invalid, the return string is specified by the string resource ATL_IDS_DATETIME_INVALID.

A brief description of the three forms for this function follows:

  • Format( dwFlags, lcid)
    This form formats the value by using the national language specifications (locale IDs) for date and time. Using the default parameters, this form will print the date and the time, unless the time portion is 0 (midnight), in which case it will print just the date, or the date portion is 0 (30 December 1899), in which case it will print just the time. If the date/time value is 0 (30 December 1899, midnight), this form with the default parameters will print midnight.

  • Format( lpszFormat)
    This form formats the value by using the format string which 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. For more information about the formatting codes, see strftime, wcsftime in the Run-Time Library Reference.

  • Format( nFormatID)
    This form formats the value by using the format string which 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. For more information about the formatting codes, see strftime, wcsftime in the Run-Time Library Reference.

Example

COleDateTime t(1999, 3, 19, 22, 15, 0);

CString str = t.Format(_T("%A, %B %d, %Y"));
ASSERT(str == _T("Friday, March 19, 1999"));   

Requirements

Header: atlcomtime.h

See Also

Reference

COleDateTime Class

Hierarchy Chart

COleDateTime::ParseDateTime

COleDateTime::GetStatus

Other Resources

COleDateTime Members