相关疑难解决方法(0)

如何从互联网上获取DateTime?

如何使用C#从互联网或服务器获取当前日期和时间?我想时间如下:

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);
}
Run Code Online (Sandbox Code Playgroud)

我正在传递服务器IP地址netServer,但它无法正常工作.

datetime c#-4.0

44
推荐指数
5
解决办法
7万
查看次数

如何通过c#或c ++获取实际日期(不是系统日期)?

是否有可能在没有任何互联网连接的情况下获得真实日期(非系统日期)?我用C#开发了我的应用程序.DateTime.Now获取系统日期但我想知道实际日期,因为系统日期可能是错误的.

可能吗?这该怎么做?

c#

4
推荐指数
1
解决办法
2967
查看次数

标签 统计

c# ×1

c#-4.0 ×1

datetime ×1