Rebex

Skip to content, Skip to navigation




Sample: TimeDifference

Shows the time difference between NTP server and local machine.

C#

Ntp client = new Ntp(args[0]);
TimeSpan offset = client.GetTime().TimeOffset.ToTimeSpan();
if (offset.Ticks >= 0)
{
	Console.Write("Server's time is {0} seconds before local time.", offset.TotalSeconds);
}
else 
{
	TimeSpan ats = new TimeSpan(-offset.Ticks);
	Console.Write("Server's time is {0} seconds behind local time.", ats.TotalSeconds);
}

VB.NET

Dim client As New Ntp(args(1))
Dim offset As TimeSpan = client.GetTime().TimeOffset.ToTimeSpan()
If offset.Ticks >= 0 Then 
    Console.Write("Server's time is {0} seconds before local time.", offset.TotalSeconds)
Else 
    Dim ats As New TimeSpan(-offset.Ticks)
    Console.Write("Server's time is {0} seconds behind local time.", ats.TotalSeconds)
End If 

It is that simple!

See also: