Partager via


Retrieving Time and Date Strings

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

The following list shows one of the most useful sets of NLS function calls.

These functions return formatted date and time picture strings.

EnumDateFormats and EnumTimeFormats enumerate the date and time picture strings that the system carries for a particular locale. With these two functions, you can build a list of possible date and time strings to present to the user.

GetDateFormat and GetTimeFormat each return a single string. When you use GetDateFormat*,* your application can request a string containing the correct date in the default short date format, DATE_SHORTDATE, or the default long date format, DATE_LONGDATE, for a particular locale.

GetTimeFormat requires valid the time values in the SYSTEMTIME structure pointed to by the lpTime parameter. The function checks each time value to determine that the value is within the appropriate range of values. If any of the time values are outside the correct range, the function fails and sets the last error to ERROR_INVALID_PARAMETER. The function ignores the date portions of the SYSTEMTIME structure pointed to by lpTime. If a time marker exists and the TIME_NOTIMEMARKER flag is not set, the function localizes the time marker, based on the specified locale identifier. Examples of time markers are "AM" and "PM" for US English, and "de." and "du". for Mexican Spanish.

GetTimeFormat does not return an error for a bad format string. The function simply forms the best time string that it can. If more than two hour, minute, second, or time marker format pictures are passed in, the function defaults to two.

In a similar manner, GetDateFormat requires valid date values in the SYSTEMTIME structure pointed to by the lpDate parameter. The function checks each of the date values: year, month, day, and day of week. If the day of the week is incorrect, the function uses the correct value and returns no error. If any of the other date values are outside the correct range, the function fails and sets the last error to ERROR_INVALID_PARAMETER. The day name, abbreviated day name, month name, and abbreviated month name are all localized based on the specified locale identifier. The function ignores the time portions of the SYSTEMTIME structure pointed to by lpDate.

To obtain the short and long date format for the default locale calendar, use the GetLocaleInfo function with the LOCALE_SSHORTDATE or the LOCALE_SLONGDATE flag. To get the date format for an alternate calendar, use GetLocaleInfo with the LOCALE_IOPTIONALCALENDAR flag. To return all the date formats for a particular calendar, use the EnumCalendarInfo or the EnumDateFormatsEx function.

To obtain the time format without performing any actual formatting, use the GetLocaleInfo function with the LOCALE_STIMEFORMAT flag set.

See Also

Reference

EnumCalendarInfo
EnumDateFormats
EnumTimeFormats
GetDateFormat
GetLocaleInfo
GetTimeFormat

Other Resources

SYSTEMTIME
Specifying Locales with NLS