//从本机获取服务器时间
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);//设置本地时间;

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2021-05-03
  • 2021-06-15
  • 2021-08-30
  • 2021-04-26
猜你喜欢
  • 2022-01-01
  • 2022-12-23
  • 2021-11-29
  • 2022-03-06
  • 2022-02-10
  • 2021-07-08
  • 2021-05-22
相关资源
相似解决方案