获取网络日期及时间

来源:互联网 发布:梦幻西游鼠标偏移源码 编辑:程序博客网 时间:2024/05/17 02:01
WebClient wc = new WebClient();
            string html = wc.DownloadString("http://time.tianqi.com/");
            int begin = html.IndexOf("北京现在时间:");
            string dateTime= html.Substring(begin+7,19);
          
            //日期
            string[] date = dateTime.Split('-');
            //年
            string year=date[0];
            //月
            string month=date[1];
            //日 date[2]="17 11:56:05";
            string day = date[2].Substring(0,2);
            //时间
            string time = date[2].Substring(2,9);
            string[] netTime = time.Split(':');
            string hour=netTime[0].Trim();
            string minute=netTime[1];
            string seconde=netTime[2];
           // MessageBox.Show("1"+hour);
            txtState.Text = year + month + day + hour + minute + seconde;
0 0
原创粉丝点击