The GetTime method will cause the calling thread to block
until the time is returned by the server, or the operation times out. If you
do not want the current thread to block, you can create a worker
thread and call this function from within that thread. The blocking
network call in the worker thread will not interfere with any other
threads in your application.
In most cases, it is preferable to use the NTP pool servers which
distribute requests over a number of different servers:
- pool.ntp.org is a global load-balanced pool of time servers
- us.pool.ntp.org servers are located in the United States
- eu.pool.ntp.org servers are located in Europe
- asia.pool.ntp.org servers are located in Asia
There are also load balanced pools of time servers available in
specific countries prefixed by their country code. For example,
the de.pool.ntp.org servers are located in Germany and
the uk.pool.ntp.org servers are located in the United Kingdom.
Regardless of their location, the time values they return are always
in Coordinated Universal Time (UTC) and are not localized based on the
physical location of the server.
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-g.nist.gov |
129.6.15.28 |
Gaithersburg, Maryland |
| time-b-g.nist.gov |
129.6.15.29 |
Gaithersburg, Maryland |
| time-nw.nist.gov |
131.107.13.100 |
Redmond, Washington |
| time-a-b.nist.gov |
132.163.96.1 |
Boulder, Colorado |
| time-b-b.nist.gov |
132.163.96.2 |
Boulder, Colorado |
| time-c-b.nist.gov |
132.163.96.3 |
Boulder, Colorado |
Time servers are also commonly maintained by government agencies and
universities. If you are unable to obtain the time from a server, contact
the system administrator to determine if they support the standard time
service available on port 123.
If you are requesting the time from a public server, you should
ensure that your application does not send too many requests over a
short period of time. In most cases, you should not query a time server
more than once per minute. Most public time servers will block the
IP address of a client which sends too many requests.
It is important to note that the network time value is not the same
as the UNIX time value used with the standard C runtime library. The
time() function returns the number of seconds since January 1, 1970
which is commonly referred to as the UNIX epoch. NTP servers return
the time as the number of seconds since January 1, 1900.