//從本機獲取服務器時間
SNTPTimeClient client = new SNTPTimeClient("10.0.5.126", "123");///////填寫你想要的獲取時間的主機的IP和端口;
client.Connect();
DateTime getEd = client.ReceiveTimestamp;//獲取指定IP的系統時間
SystemTime st = new SystemTime
{
wDay = (ushort)getEd.Day,
wDayOfWeek = (ushort)getEd.DayOfWeek,
wHour = (ushort)getEd.Hour,
wMiliseconds = (ushort)getEd.Millisecond,
wMinute = (ushort)getEd.Minute,
wMonth = (ushort)getEd.Month,
wSecond = (ushort)getEd.Second,
wYear = (ushort)getEd.Year
};
SNTPTimeClient.SetLocalTime(st);//設置本地時間;