GetDurationFormatEx function (winnls.h)
Formats a duration of time as a time string for a locale specified by name.
int GetDurationFormatEx( LPCWSTR lpLocaleName, DWORD dwFlags, const SYSTEMTIME *lpDuration, ULONGLONG ullDuration, LPCWSTR lpFormat, LPWSTR lpDurationStr, int cchDuration );
Pointer to a locale name, or one of the following predefined values.
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.
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.
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.
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.
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.
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.
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:
- ERROR_INSUFFICIENT_BUFFER. A supplied buffer size was not large enough, or it was incorrectly set to NULL.
- ERROR_INVALID_PARAMETER. Any of the parameter values was invalid.
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:
Formatting characters are lowercase.
Note An exception is made for (H) to be consistent with GetTimeFormatEx.
- Two-digit format strings for hours, minutes, and seconds prepend a leading zero if the value is less than 10.
- The first output field is not subject to any bounds testing (hours<24, minutes<60, seconds<60, milliseconds<1000). Days are not subject to bounds testing.
- The function assumes that all format strings are in decreasing field size, for example, hours, minutes, seconds, milliseconds.
- The first field to be displayed is normalized, as defined by the format string. For example, if the application specifies 310 seconds and the format string is m:ss, the output is 5:10. However, if the format string specifies minutes and seconds but the application specifies hours, the minutes field is adjusted accordingly.
- If fractions are not the first field, the number of "f" characters in the format string indicates the number of decimals to show (limit of 9). If fractions are the first field, the number of "f" characters indicates the number of significant digits below one second.
- Round-off occurs by truncation, not by the rule of five rounds up and four rounds down.
- Single quotes are used to escape characters.
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
|h' h 'mm' m 'ss' s'||338 h 45 m 12 s|
SYSTEMTIME = 345 seconds
|mm' m 'ss' s'||05 m 45 s|
|ss' seconds'||345 seconds|
uulDuration = 51234567 (5.1234567 seconds)
|ss:fffffffff||5.123456700 (add trailing zeros)|
|fff 'ms'||5123 ms|
|ffffff 'microseconds'||5123456 microseconds|
|fffffffff 'ns'||5123456700 ns|
|Minimum supported client||Windows Vista [desktop apps | UWP apps]|
|Minimum supported server||Windows Server 2008 [desktop apps | UWP apps]|
|Header||winnls.h (include Windows.h)|