简体   繁体   English

如何在C#中的应用程序中在客户端获取远程服务器的日期和时间?

[英]How can I get the remote server's date and time at the client side in my application in c#?

我在应用程序中为用户设置了截止时间,因此,我不想考虑当前的系统时间,而是希望考虑远程服务器计算机的时间,因此如何在c#中获取远程服务器的日期和时间。

Write a request handler on your server that sends the date time. 在您的服务器上编写一个发送日期时间的请求处理程序。 Without more details, its difficult to know how to implement that. 没有更多细节,很难知道如何实现。

Write a simple web service that when invoked returns the timestamp (possibly using UTC or something). 编写一个简单的Web服务,该服务在被调用时将返回时间戳(可能使用UTC或其他方式)。

[WebMethod]
    public string ServerDateTime()
    {
        serverDate = DateTime.UtcNow;
        return serverDate.ToString();
    }

You could be even lazier and have a standard asp.net page that has the same web method as well. 您甚至可能变得懒惰,并且拥有具有相同Web方法的标准asp.net页面。 Example: http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!484.entry 示例: http//softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!484.entry

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM