class UpdateDateTime
{
[DllImport("Kernel32.dll")]
private static extern void SetLocalTime([In, Out] SystemTime st); public static void UpdateTime()
{
Uri uri = new Uri("http://www.beijing-time.org/time15.asp");
WebRequest request = WebRequest.Create(uri);
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gbk")); string html = reader.ReadToEnd();
reader.Close();
reader.Dispose();
response.Close(); if (html[html.Length-].Equals(';'))
{
html = html.Remove(html.Length - );
} string[] arr = html.Split(';');
SystemTime st = new SystemTime(); foreach (string str in arr)
{
switch (str.Split('=')[].Trim().ToLower())
{
case "nyear":
st.Year = Convert.ToInt16(str.Split('=')[]);
break;
case "nmonth":
st.Month = Convert.ToInt16(str.Split('=')[]);
break;
case "nday":
st.Day = Convert.ToInt16(str.Split('=')[]);
break;
case "nhrs":
st.Hour = Convert.ToInt16(str.Split('=')[]);
break;
case "nmin":
st.Minute = Convert.ToInt16(str.Split('=')[]);
break;
case "nsec":
st.Second = Convert.ToInt16(str.Split('=')[]);
break;
}
}
SetLocalTime(st);
}
} [StructLayout(LayoutKind.Sequential)]
class SystemTime
{
///
///系统时间类
///
public short Year;
public short Month;
public short DayOfWeek;
public short Day;
public short Hour;
public short Minute;
public short Second;
public short Milliseconds;
}

c# 获取北京时间更新本地计算机的更多相关文章

  1. C#获取北京时间与设置系统时间

    获取北京时间 public static DateTime GetBeijingTime() { DateTime dt; // 返回国际标准时间 // 只使用 timeServers 的 IP 地址 ...

  2. atitit.获取北京时间CST 功能api总结 O7

    atitit.获取北京时间CST 功能api总结 O7 1. 获取cst时间(北京时间)两布:1.抓取url timtstamp >>format 到cst 1 2. 设置本机时间  se ...

  3. python获取网络时间和本地时间

    今天我们来看一下如何用python获取网络时间和本地时间,直接上代码吧,代码中都有注释. python获取网络时间 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  4. C#获取获取北京时间多种方法

    #region 获取网络时间 ///<summary> /// 获取中国国家授时中心网络服务器时间发布的当前时间 ///</summary> ///<returns> ...

  5. C# 获取北京时间 (根据纪元时间(1970/1/1)转换为DateTime)

    根据纪元时间(1970/1/1)转换为DateTime WebClient wc = new WebClient(); s= wc.DownloadString("http://api.ti ...

  6. delphi 获取北京时间(使用XMLHTTP获取百度的时间,WebBrowser获取www.timedate.cn的时间)

    方法一: uses ComObj, DateUtils; function GetInternetTime: string; var XmlHttp: OleVariant; datetxt: str ...

  7. Delphi 获取北京时间(通过百度和timedate网站)

    方法一: uses ComObj, DateUtils; function GetInternetTime: string; var XmlHttp: OleVariant; datetxt: str ...

  8. js 获取北京时间

    <SCRIPT LANGUAGE = "JavaScript"> var xmlhttp = new ActiveXObject("MSXML2.XMLHTT ...

  9. Unity 获取服务器时间 HTTP请求方式

    在写每日签到的时候,我居然使用的是本地时间...被项目经理笑哭了...., 如果你在写单机游戏,没有游戏服务器,但又不想使用本地时间,就可以采用下面方法. 方法总结: 1. 使用HTTP请求获取服务器 ...

随机推荐

  1. Bootstrap 3之美04-自定义CSS、Theme、Package

    本篇主要包括: ■  自定义CSS■  自定义Theme■  自定义Package 自定义CSS 有时候,需要自定义或重写Bootstrap默认的CSS.→在css文件夹下创建一个site.css→假 ...

  2. MVC中使用AngularJS-01,基本

    Angularjs是一个前端的Javascript MVC 库和框架,使前端得到更好的设计.维护和测试.它的核心特性有:MVC.双向数据绑定.指令和语义化标签.模块化工具.依赖注入.HTML模板,以及 ...

  3. spring事务的隔离级别(透彻理解)

    1.spring 事务这个东西,是轮子,每个service,都需要用到.所以干脆就做在框架层实现. 2.spring是怎么给你的service方法加事务的呢?jdk动态代理,会针对每个service类 ...

  4. [Apache] Apache 從 2.2 換至 2.4 httpd.conf 的調整筆記 (windows 環境)

    原文地址: http://www.dotblogs.com.tw/maplenote/archive/2012/07/20/apache24_httpd_conf.aspx 整理一下 Windows ...

  5. Android开发FAQ集锦!!!

    .Android SDK应该从什么地方下载?为什么(http://developer.Android.com/ )经常上不上去? 答:谷歌官网的 (http://developer.Android.c ...

  6. remotepath != null 与 !TextUtils.isEmpty(remotepath) 的差别

    remotepath != null   与 !TextUtils.isEmpty(remotepath) 的差别 !TextUtils.isEmpty(remotepath)    与   remo ...

  7. dtree实现动态加载树形菜单,动态插入树形菜单

    1.导入  dtree文件    dtree.css   img文件夹   dtree.js 2. 建立对应 的数据库      1      父ID     name    id 3    建立连接 ...

  8. 如何高效把一字节的位对换, bit0和bit7,bit1和bit6,以此类推.

    #include<stdio.h> #include<stdlib.h> //异或法 unsigned char byteReverse(unsigned char val) ...

  9. leetcode笔记:Same Tree

    一. 题目描写叙述 Given two binary trees, write a function to check if they are equal or not. Two binary tre ...

  10. @JVM垃圾回收机制的一些概念

    数据类型 Java虚拟机中,数据类型可以分为两类:基本数据类型和引用数据类型 .基本类型的变量保存的值就是数值本身:而引用类型的变量保存引用值."引用值"代表了某个对象的引用,而不 ...