Share via


DateTime_SetFormat

This macro sets the display of a date and time picker (DTP) control based on a specified format string.

BOOL DateTime_SetFormat(
HWND hwndDT, 
LPCTSTR lpszFormat);

Parameters

  • hwndDT
    Handle to a DTP control.
  • lpszFormat
    Long pointer to a null-terminated format string that defines the desired display. Setting this parameter to NULL will reset the control to the default format string for the current style. The format string is a combination of string fragments. It is interpreted literally, with the exception of the following string fragments.
    Value Description
    d The one- or two-digit day.
    dd The two-digit day. Single-digit day values are preceded by a zero.
    ddd The three-character weekday abbreviation.
    dddd The full weekday name.
    h The one- or two-digit hour in 12-hour format.
    hh The two-digit hour in 12-hour format. Single-digit values are preceded by a zero.
    H The one- or two-digit hour in 24-hour format.
    HH The two-digit hour in 24-hour format. Single-digit values are preceded by a zero.
    m The one- or two-digit minute.
    mm The two-digit minute. Single-digit values are preceded by a zero.
    M The one- or two-digit month number.
    MM The two-digit month number. Single-digit values are preceded by a zero.
    MMM The three-character month abbreviation.
    MMMM The full month name.
    t The one-letter AM/PM abbreviation (that is, AM is displayed as A).
    tt The two-letter AM/PM abbreviation (that is, AM is displayed as AM).
    X A callback field. The control still uses the other valid format characters, and queries the owner to fill in the X portion. Therefore, the owner must be prepared to handle the DTN_WMKEYDOWN, DTN_FORMAT, and DTN_FORMATQUERY notification messages. Multiple X characters can be used to signify unique callback fields.
    y The year is displayed as the last two digits, but with no leading zero for years less than 10.
    yy The last two digits of the year (that is, 1998 would be displayed as 98).
    yyy The full year (that is, 1998 would be displayed as 1998).

Return Values

Returns TRUE if successful, or FALSE otherwise.

Remarks

It is acceptable to include extra characters within the format string to produce a richer display. However, any nonformat characters must be enclosed within single quotes. For example, the format string Today is: hh:m:s ddddMMMdd, yyy would produce output like Today is: 04:22:31 Tuesday Mar 23, 1996.

No errors are returned for a bad format string. The function simply forms the best date string that it can. For example, the only year pictures that are valid are Lyyyy and Lyy (the L indicates a Unicode (16-bit characters) string). If Ly is passed in, the function assumes Lyy. If Lyyy is passed in, the function assumes Lyyyy. If more than 4 date (dddd) or 4 month (LMMMM) pictures are passed in, then the function defaults to Ldddd or LMMMM.

Any text that should remain in its exact form in the date string should be enclosed within single quotation marks in the date format picture. The single quotation mark may also be used as an escape character to allow the single quotation mark itself to be displayed in the date string. However, the escape sequence must be enclosed within two single quotation marks. For example, to display the date as May 93, the format string would be: LMMMM yy. The first and last single quotation marks are the enclosing quotation marks. The second and third single quotation marks are the escape sequence to allow the single quotation mark to be displayed before the century.

Note A DTP control tracks locale changes when it is using the default format string. If you set a custom format string, it will not be updated in response to locale changes.

Requirements

Runs On Versions Defined in Include Link to
Windows CE OS 1.0 and later Commctrl.h   Commctrl.lib

Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also

DTM_SETFORMAT

 Last updated on Tuesday, July 13, 2004

© 1992-2000 Microsoft Corporation. All rights reserved.