title: How to get DateTime from the internet?
body: <p>How to get current date and time from internet or server using C#? I am trying to get time as follows:</p>
  
  <pre><code>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);
  }
  </code></pre>
  
  <p>I am passing server IP address as <code>netServer</code>, but it does not work properly.</p>