Как получить текущую дату и время из Интернета или сервера с помощью С#? Я пытаюсь получить время следующим образом:
public static DateTime GetNetworkTime (string ntpServer)
{
IPAddress[] address = Dns.GetHostEntry(ntpServer).AddressList;
if (address == null || address.Length == 0)
throw new ArgumentException("Could not resolve ip address from '" + ntpServer + "'.", "ntpServer");
IPEndPoint ep = new IPEndPoint(address[0], 123);
return GetNetworkTime(ep);
}
Я передаю IP-адрес сервера как netServer
, но он не работает должным образом.