如何使用C#從Internet或服務器獲取當前日期和時間?我正在嘗試獲取時間,如下所示: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,但無法正常工作。
- 3 回答
- 0 關注
- 491 瀏覽
添加回答
舉報
0/150
提交
取消