WebGetSystemTime Function  
 
BOOL WINAPI WebGetSystemTime(
  DWORD dwOptions,  
  LPSYSTEMTIME lpDateTime  
);

The WebGetSystemTime function returns the current date and time in a SYSTEMTIME structure.

Parameters

dwOptions
An integer parameter which specifies one or more options.
Value Description
WEB_TIME_DEFAULT The default options should be used when retrieving the date and time. This is the same as specifying WEB_TIME_UNIVERSAL.
WEB_TIME_UNIVERSAL The date and time values returned in the SYSTEMTIME structure will use Universal Coordinated Time (UTC) and will not be adjusted for the current timezone. This is similar to the value returned by the GetSystemTime function in the Win32 API.
WEB_TIME_LOCAL The date and time values returned in the SYSTEMTIME structure will adjusted for the current timezone. This is similar to the value returned by the GetLocalTime function in the Win32 API. The local timezone is determined by system settings for the current user.
lpDateTime
A pointer to a SYSTEMTIME structure which contains the current date and time. The structure members will be initialized to zero when the function is called and then updated when it returns successfully. This parameter cannot be NULL or the function will fail.

Return Value

If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To get extended error information, call WebGetLastError.

Remarks

The WebGetSystemTime function returns the current date and time into a SYSTEMTIME structure. Unlike the GetSystemTime function, this function does not use the local system clock. Instead, it obtains the current time from the SocketTools API server, which is synchronized with official time servers using the Network Time Protocol (NTP). This helps ensure that the returned value is accurate and has not been altered by the user or affected by incorrect system clock settings.

This function can be useful in scenarios where an application must rely on a trusted and consistent time source. For example, it may be used for validating software licenses, enforcing time-based restrictions, generating timestamps for logging or auditing, or coordinating events across multiple systems where the local system time cannot be assumed to be accurate.

Because the time value is retrieved from a remote server, this function requires an active network connection and may be subject to network latency or temporary connectivity issues. To reduce network overhead, the function internally caches the most recently retrieved time value for a short period (typically up to 60 seconds). When the function is called again within this interval, it does not immediately query the server. Instead, it calculates the elapsed time since the last successful request using a high-resolution system tick count and adjusts the cached time value accordingly.

This approach allows the returned time to continue advancing between server synchronizations, providing a smooth and consistent progression of time values without requiring a network request for each call. However, because this adjustment is based on the local system timer, it should be considered an approximation of the actual server time. The time value will be re-synchronized with the server periodically to maintain overall accuracy.

In most cases, it is recommended that applications use the WEB_TIME_UNIVERSAL option when storing or comparing date/time values. Universal (UTC) time provides a consistent, timezone-independent reference that avoids issues related to daylight saving time changes or differences in local system settings. This is particularly important when timestamps are shared between systems or persisted for later comparison.

The WEB_TIME_LOCAL option can be used when the application requires a date/time value adjusted for the user's current timezone, such as when displaying timestamps in a user interface. However, because the timezone adjustment is based on the local system configuration, it may still be affected by incorrect timezone or daylight saving settings on the client system.

Developers should consider using the local system time (for example, via GetSystemTime or GetLocalTime) when absolute accuracy is not critical or when network access is unavailable. Retrieving the time locally avoids the overhead of a network request and is typically sufficient for general-purpose tasks such as UI updates, file timestamps, or short-lived timing operations.

This function is not intended to replace standard system time APIs for high-frequency or real-time operations. Applications that require precise time measurements or guaranteed monotonic behavior should use dedicated high-resolution timing APIs instead of relying on this function.

Example

SYSTEMTIME stDateTime;

if (WebGetSystemTime(WEB_TIME_UNIVERSAL, &stDateTime))
{
    // Display the current date and time in ISO 8601 format
    _tprintf(_T("The current date and time is %04hu-%02hu-%02huT%02hu:%02hu:%02huZ\n"),
             stDateTime.wYear,
             stDateTime.wMonth,
             stDateTime.wDay,
             stDateTime.wHour,
             stDateTime.wMinute,
             stDateTime.wSecond);
}
else
{
  DWORD dwError = WebGetLastError();
  _tprintf(_T("Unable to determine the current date and time, error 0x%08lx\n"), dwError);
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cswebv12.lib

See Also