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

    PROTOBUF的DELPHI开源框架fundamentals5 GITHUB: https://github.com/fundamentalslib/fundamentals5 # Fundamen ...

  2. 0, \0, NULL

    字符串.字符数组输入.输出与'\0'的问题 原创首发,欢迎转载! 作者按 字符串.字符数组以"%s"格式输入时,以遇到'空格'为这个字符串输入结束. 字符串.字符数组以" ...

  3. 如何获取隔壁wifi密码,非暴力破解

    目前常见的Wi-Fi加密方式有WEP.WPA2和WPS(链接为各自的破解方式),不过有网友反映以往破解WPA2的方法耗时太长,而且不适用于所有WPS启动的接入点.而今天介绍的这种方法则更加省时省力. ...

  4. 混沌数学之Kent模型

    相关软件:混沌数学之离散点集图形DEMO 相关代码: // http://wenku.baidu.com/view/7c6f4a000740be1e650e9a75.html // 肯特映射 clas ...

  5. [leetcode]Populating Next Right Pointers in Each Node II @ Python

    原题地址:https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/ 题意: Follow up ...

  6. [leetcode]Binary Tree Level Order Traversal II @ Python

    原题地址:http://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/ 题意: Given a binary tree, ...

  7. [leetcode]Reorder List @ Python

    原题地址:http://oj.leetcode.com/problems/reorder-list/ 题意: Given a singly linked list L: L0→L1→…→Ln-1→Ln ...

  8. 网络结构设计——负载均衡之LVS学习笔记(四)

    LVS按个人理解的说就是将一台Linux服务器当作路由器等功能的技术.LVS---Linux虚拟服务器. LVS实现了三种IP负载均衡技术VS/NAT.VS/TUN.VS/DR. 今天简单分享一下我在 ...

  9. 【5】基于Log4Net的日志系统

    阅读目录 日志系统应具备的特性  Log4Net 配置文件:log4net.config 初始化 输出信息 对Log4Net的封装 log4net.config复杂配置   不管是Web应用程序还是W ...

  10. php5.2以下版本无json_decode函数的解决办法

    function json_decode2($json) { $comment = false; $out = '$x=';   for ($i=0; $i<strlen($json); $i+ ...