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, rather than 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.lpszFormat
A formatting string similar to the printf formatting string. Formatting codes, preceded by a percent (%) sign, are 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 details. 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
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 IDS_INVALID_DATETIME.
A brief description of the three forms for this function follows:
Format( dwFlags**,** lcid )
This form formats the value 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 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 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.
For a listing of locale ID values, see the section Supporting Multiple National Languages in the Windows SDK.
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