简体   繁体   中英

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).

[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. Example: http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!484.entry

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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