Export (0) Print
Expand All

WinHttpTimeFromSystemTime function

The WinHttpTimeFromSystemTime function formats a date and time according to the HTTP version 1.0 specification.

Syntax


BOOL WINAPI WinHttpTimeFromSystemTime(
  _In_   const SYSTEMTIME *pst,
  _Out_  LPWSTR pwszTime
);

Parameters

pst [in]

A pointer to a SYSTEMTIME structure that contains the date and time to format.

pwszTime [out]

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 CodeDescription
ERROR_WINHTTP_INTERNAL_ERROR

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.

Note  For Windows XP and Windows 2000, see the Run-Time Requirements section of the WinHTTP Start Page.

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

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]

Redistributable

WinHTTP 5.0 and Internet Explorer 5.01 or later on Windows XP and Windows 2000.

Header

Winhttp.h

Library

Winhttp.lib

DLL

Winhttp.dll

See also

About Microsoft Windows HTTP Services (WinHTTP)
WinHttpTimeToSystemTime
WinHTTP Versions

 

 

Community Additions

ADD
Show:
© 2014 Microsoft