获取服务器时间,并在本地处理。QQ:267307031

1.通过webservice获取服务器时间:

[WebMethod(Description = "获取服务器时间")]
        public DateTime getDateTime()
        {
            return System.DateTime.Now;
        }

2.程序中访问webservice获取服务器时间。

 DateTime dtDate =Common.DateTime.getDateTime();

3.在程序中,处理服务器时间。(应先添加一个时钟,然后启用,)

启用的时钟Time1的Interval:1000。出发下面的事件:

private void timer1_Tick(object sender, EventArgs e)
        {
            dtDate = dtDate.AddSeconds(1);
            this.toolStripStatusLabel2.Text = "时间: " + dtDate.ToLongTimeString();

//注意,不可以写成  this.toolStripStatusLabel2.Text = "时间: " + dtDate.AddSeconds(1).ToLongTimeString();

//因为这个东西,这么写的话,dtDate不更新。
        }

/*
以上内容为本人业余时间整理,部分内容来源网络,如有错误欢迎各位批评指正。


*/
原文地址:https://www.cnblogs.com/Lin267307031/p/2696556.html