WinHttpTimeFromSystemTime function (winhttp.h)
The WinHttpTimeFromSystemTime function formats a date and time according to the HTTP version 1.0 specification.
Syntax
WINHTTPAPI BOOL WinHttpTimeFromSystemTime(
[in] const SYSTEMTIME *pst,
[out] LPWSTR pwszTime
);
Parameters
[in] pst
A pointer to a SYSTEMTIME structure that contains the date and time to format.
[out] pwszTime
A pointer to a string buffer that receives the formatted date and time. The buffer should equal to the size, in bytes, of WINHTTP_TIME_FORMAT_BUFSIZE.
Return value
Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError. Error codes include the following.
Error Code | Description |
---|---|
|
An internal error has occurred. |
Remarks
Even when WinHTTP is used in asynchronous mode (that is, when WINHTTP_FLAG_ASYNC has been set in WinHttpOpen), this function operates synchronously. The return value indicates success or failure. To get extended error information, call GetLastError.
Examples
The following code example code shows how to convert a SYSTEMTIME structure to a string that contains the time in HTTP format.
SYSTEMTIME sTime;
LPWSTR pwszTimeStr;
// Get the current time.
GetSystemTime(&sTime);
// Allocate memory for the string.
// Note: WINHTTP_TIME_FORMAT_BUFSIZE is a byte count.
// Therefore, you must divide the array by
// sizeof WCHAR to get the proper string length.
pwszTimeStr = new WCHAR[WINHTTP_TIME_FORMAT_BUFSIZE/sizeof(WCHAR)];
// Convert the current time to HTTP format.
if(!WinHttpTimeFromSystemTime( &sTime, pwszTimeStr))
{
printf( "Error %u in WinHttpTimeFromSystemTime.\n", GetLastError());
}
else
{
// Print the time.
printf("Current time is (%S)\n", pwszTimeStr);
}
// Free the memory.
delete [] pwszTimeStr;
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows XP, Windows 2000 Professional with SP3 [desktop apps only] |
Minimum supported server | Windows Server 2003, Windows 2000 Server with SP3 [desktop apps only] |
Target Platform | Windows |
Header | winhttp.h |
Library | Winhttp.lib |
DLL | Winhttp.dll |
Redistributable | WinHTTP 5.0 and Internet Explorer 5.01 or later on Windows XP and Windows 2000. |