SocketTools .NET Edition

NetworkTime.SetTime Method (String)

Set the local system clock to the current date and time as returned by the specified time server.

[Visual Basic]
Overloads Public Function SetTime( _
   ByVal hostName As String _
) As Boolean
[C#]
public bool SetTime(
   string hostName
);

Parameters

hostName
A string which specifies the host name or address of the time 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

The SetTime method updates the local system clock to the date and time returned by the time server. The user must have the appropriate privileges to change the system clock, otherwise an error will be returned. This typically requires the application to execute with elevated privileges.

Because Windows systems are usually configured to automatically synchronize the system clock with a time server using the Windows Time service (W32Time), most applications should not use this method. If there is a significant discrepancy between the local system time and the several different time servers, the recommended course of action is to warn the user and prompt them to check their system settings and ensure the Windows Time service is running.

See Also