Synchronize

Synchronize

The sample asks a time server for time difference and uses the answer to update time on the local machine.

Usage

The sample synchronizes local computer time with the time server.

> Synchronize pool.ntp.org

C#

Console.Write("Local time is {0}.", DateTime.Now);

// get NTP server response
Ntp client = new Ntp(args[0]);
NtpResponse response = client.GetTime();

// show the time offset received
Console.Write("Moving local time by {0}.", response.TimeOffset.ToTimeSpan());

// adjust local time
SystemClock.AdjustClock(response);

VB.NET

Console.Write("Local time is {0}.", DateTime.Now)

' get NTP server response
Dim client As Ntp = New Ntp(args(1))
Dim response As NtpResponse = client.GetTime()

' show the time offset received
Console.Write("Moving local time by {0}.", response.TimeOffset.ToTimeSpan())

' adjust local time
SystemClock.AdjustClock(response)

Included in

See also: