SocketTools .NET Edition

NetworkTime.GetTime Method (String, Int32, Int32, boolean, DateTime)

Get the current date and time from the specified time server.

[Visual Basic]
Overloads Public Function GetTime( _
   ByVal hostName As String, _
   ByVal hostPort As Integer, _
   ByVal timeout As Integer, _
   ByVal localize As Boolean, _
   ByRef dateTime As Date _
) As Boolean
[C#]
public bool GetTime(
   string hostName,
   int hostPort,
   int timeout,
   bool localize,
   ref DateTime dateTime
);

Parameters

hostName
A string which specifies the host name or IP address of the time server.
hostPort
An integer value which specifies the port to connect to on the server. The default port value for a time server is port 37.
timeout
An integer value which specifies the number of seconds until a blocking operation fails and returns an error.
localize
A boolean value which specifies if the time should be adjusted for the local timezone. A value of true specifies the time should be adjusted and a value of false specifies the time should be returned as a Coordinated Universal Time (UTC) value.
dateTime
A System.DateTime structure passed by reference which will contain the date and time returned by the server.

Return Value

This method returns a boolean value. If the method succeeds, the return value is true. If the method fails, the return value is false. To get extended error information, check the value of the LastError property.

Remarks

Time servers are commonly maintained by governments 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 or 123.

In the United States, the National Institute of Standards and Technology (NIST) hosts public servers which can be used to obtain the current time. It is recommended most applications use time.nist.gov as the server. Public servers should not be queried frequently and may block multiple requests issued over a short period of time.

See Also

NetworkTime Class | SocketTools Namespace | NetworkTime.GetTime Overload List