GetNetworkTime Function  
 
DWORD WINAPI GetNetworkTime(
  LPCTSTR lpszRemoteHost,  
  UINT nRemotePort,  
  UINT nTimeout  
);

The GetNetworkTime function returns the network time from the specified host. The network time is a 32-bit number, represented as the number of seconds since midnight, 1 January 1900 UTC.

Parameters

lpszRemoteHost
A pointer to the name of the server. The host must be running a time server that complies with the specifications outlined in RFC 868.
nRemotePort
The port the time server is running on. A value of zero indicates that the default port number for the service should be used.
nTimeout
The number of seconds that the function will wait for a response from the server.

Return Value

If the function succeeds, it returns the number of seconds since midnight, 1 January 1900 UTC. If the function was unable to obtain the time from the specified host, it returns zero.

Remarks

The GetNetworkTime function will cause the calling thread to block until the time is returned by the server, or the operation times out. For applications which require asynchronous operation, the QueryNetworkTime function should be used instead.

The network time value can represent a date and time up to the year 2036. It is important to note that the network time value is not the same as the UNIX time value that is used the standard C library time functions.

In the United States, the National Institute of Standards and Technology (NIST) hosts a number of public servers which can be used to obtain the current time. The following table lists the current host names and addresses:

Server Name IP Address Location
time-a.nist.gov 129.6.15.28 Gaithersburg, Maryland
time-b.nist.gov 129.6.15.29 Gaithersburg, Maryland
time-nw.nist.gov 131.107.13.100 Redmond, Washington
time-a.timefreq.bldrdoc.gov 132.163.4.101 Boulder, Colorado
time-b.timefreq.bldrdoc.gov 132.163.4.102 Boulder, Colorado
time-c.timefreq.bldrdoc.gov 132.163.4.103 Boulder, Colorado

Time servers are also commonly maintained by Internet service providers and universities. If you are unable to obtain the time from a server, contact the system administrator to determine if they have the standard time service available on port 37.

Requirements

Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header File: cstools10.h
Import Library: cstimv10.lib
Unicode: Implemented as Unicode and ANSI versions.

See Also

ConvertNetworkTime, QueryNetworkTime, ReadNetworkTime, TimeInitialize