Formats a duration of time as a time string for a locale specified by name.
Note
The application should call this function in preference to GetDurationFormat if designed to run only on Windows Vista and later.
Note
This function can format data that changes between releases, for example, due to a custom locale. If your application must persist or transmit data, see Using Persistent Locale Data.
int GetDurationFormatEx(
LPCWSTR lpLocaleName,
DWORD dwFlags,
const SYSTEMTIME *lpDuration,
ULONGLONG ullDuration,
LPCWSTR lpFormat,
_Out_writes_opt_(cchDuration)LPWSTR lpDurationStr,
int cchDuration
)
lpLocaleName
Type: LPCWSTR
Pointer to a locale name, or one of the following predefined values.
dwFlags
Type: DWORD
Flags specifying function options. If lpFormat is not set to NULL, this parameter must be set to 0. If lpFormat is set to NULL, your application can specify LOCALE_NOUSEROVERRIDE to format the string using the system default duration format for the specified locale.
Caution
Use of LOCALE_NOUSEROVERRIDE is strongly discouraged as it disables user preferences.
lpDuration
Type: SYSTEMTIME *
Pointer to a SYSTEMTIME structure that contains the time duration information to format. The application sets this parameter to NULL if the function is to ignore it and use ullDuration.
ullDuration
Type: ULONGLONG
64-bit unsigned integer that represents the number of 100-nanosecond intervals in the duration. If both lpDuration and ullDuration are set, the lpDuration parameter takes precedence. If lpDuration is set to NULL and ullDuration is set to 0, the duration is 0.
lpFormat
Type: LPCWSTR
Pointer to the format string with characters as shown below. The application can set this parameter to NULL if the function is to format the string according to the duration format for the specified locale. If lpFormat is not set to NULL, the function uses the locale only for information not specified in the format picture string.
lpDurationStr
Type: Out_writes_opt(cchDuration)LPWSTR
Pointer to the buffer in which the function retrieves the duration string.Alternatively, this parameter retrieves NULL if cchDuration is set to 0. In this case, the function returns the required size for the duration string buffer.
cchDuration
Type: int
Size, in characters, of the buffer indicated by lpDurationStr.Alternatively, the application can set this parameter to 0. In this case, the function retrieves NULL in lpDurationStr and returns the required size for the duration string buffer.
Type: int
Returns the number of characters retrieved in the buffer indicated by lpDurationStr if successful. If lpDurationStr is set to NULL and cchDuration is set to 0, the function returns the required size for the duration string buffer, including the terminating null character. For example, if 10 characters are written to the buffer, the function returns 11 to include the terminating null character.
The function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError, which can return one of the following error codes:
This function can be used with multimedia applications that display file time and sporting event applications that display finish times.
This function can retrieve data from custom locales. Data is not guaranteed to be the same from computer to computer or between runs of an application. If your application must persist or transmit data, see Using Persistent Locale Data.
The following are characteristics of duration format strings:
Note An exception is made for (H) to be consistent with GetTimeFormatEx.
Beginning in Windows 8: If your app passes language tags to this function from the Windows.Globalization namespace, it must first convert the tags by calling ResolveLocaleName.
Examples
Following are examples of duration formats and corresponding outputs for specified time durations.
SYSTEMTIME = 14 days, 2 hours, 45 minutes, 12 seconds, and 247 milliseconds
| Format | Output |
|---|---|
| d:hh:mm:ss | 14:02:45:12 |
| hh:mm:ss:ff | 338:45:12.24 |
| hh:mm:ss:fff | 338:45:12.247 |
| h’ h ‘mm’ m ‘ss’ s’ | 338 h 45 m 12 s |
SYSTEMTIME = 345 seconds
| Format | Output |
|---|---|
| hh:mm:ss | 00:05:45 |
| h:mm:ss | 0:05:45 |
| mm:ss | 05:45 |
| m:ss | 5:45 |
| mm’ m ‘ss’ s’ | 05 m 45 s |
| ss | 345 |
| ss’ seconds’ | 345 seconds |
uulDuration = 51234567 (5.1234567 seconds)
| Format | Output |
|---|---|
| ss:fff | 5.123 |
| ss:ffffff | 5.123456 |
| ss:fffffffff | 5.123456700 (add trailing zeros) |
| fff ‘ms’ | 5123 ms |
| ffffff ‘microseconds’ | 5123456 microseconds |
| fffffffff ‘ns’ | 5123456700 ns |
Windows Phone 8: This API is supported.
Header: Declared in winnls.h.
Library: Use kernelx.lib.