Internationalization and localization tools


Locale-Sensitive Windows C++ Function

int GetTimeFormat(LCID Locale, DWORD dwFlags, CONST SYSTEMTIME *lpTime, LPCTSTR lpFormat, LPTSTR lpTimeStr, int cchTime);

int GetTimeFormatA(LCID Locale, DWORD dwFlags, CONST SYSTEMTIME *lpTime, LPCSTR lpFormat, LPSTR lpTimeStr, int cchTime);

int GetTimeFormatW(LCID Locale, DWORD dwFlags, CONST SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, int cchTime);

Internationalization (I18n) Function Overview

The GetTimeFormat function formats the time variable lpTime based on the locale specified by Locale and the options specified by dwFlags and lpFormat, and stores the resulting time string in lpTimeStr. If successful, it returns the number of TCHARs, including the null-terminating character, written to lpTimeStr. In the event of an error, GetTimeFormat returns 0 and sets extended error information that can be obtained by calling GetLastError.

cchTime should be set to either the size, in TCHARs, of the lpTimeStr buffer, or to 0, in which case, the function returns the number of TCHARs required to hold the information, and the buffer pointed to by lpTimeStr is not used.

GetTimeFormatA is the narrow version of the function, where lpFormat and lpTimeStr are single or multibyte strings and cchTime and the return are byte length values.

GetTimeFormatW is the wide version of the function, where lpFormat and lpTimeStr are wide-character strings and cchTime and the return are wide-character (WCHAR) length values.

See the MSDN Library for additional information.

I18n Issues

Use the appropriate version of the function as required for internationalization support, noting the following:

Formulate the correct locale to pass into GetTimeFormat. Although there are two predefined LCID constants that may be used: LOCALE_SYSTEM_DEFAULT (the system's default locale returned by GetSystemDefaultLCID) and LOCALE_USER_DEFAULT (the current user's default locale returned by GetUserDefaultLCID), neither of these will work in an internationalized application where the locale is independent of the user's system settings.

Ensure that if cchTime is non-zero, it is set correctly for the chosen platform; bytes for the narrow version and WCHARs for the wide version. See Locale-Sensitive Length Functions for a discussion on multibyte and wide character sizes.

Recommended Replacements*

When possible, use the Generic version of the function, rather than the narrow or wide versions, and let the Windows #define UNICODE switch determine which version of the function will be called.

*If you're already using the recommended function, see I18n Issues for other reasons why Globalyzer is detecting the function.

Locale-Sensitive Windows C++ Functions

 

Lingoport internationalization and localization services and software