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. 线程系列06,通过CLR代码查看线程池及其线程

    在"线程系列04,传递数据给线程,线程命名,线程异常处理,线程池"中,我们已经知道,每个进程都有一个线程池.可以通过TPL,ThreadPool.QueueUserWorkItem ...

  2. 调试查看CLR运行代码

    SOS (Son of Strike)调试扩展可以让我们在调试过程中查看CLR运行代码.SOS.dll随.NET一起安装,对于.NET 4.0来说,SOS.dll的所在位置是:C:\Windows\M ...

  3. C#程序集系列04,在程序集包含多个module的场景下理解关键字internal

    本篇在一个程序集包含多个module的场景下体验internal的含义. →查看F盘as文件夹下的文件→删除MainClass.exe→把MyFirstModule和MySecondModule组装到 ...

  4. jsondataobjects

    jsondataobjects GITHUB: https://github.com/ahausladen/jsondataobjects.git 跨平台JSON库 Json Data Objects ...

  5. 如何让access空值变成0?(确切的说是让access Null值变成0)

    方法一 if  IsNull(Me.新_退休费) = True Then Me.新_退休费 = 0 方法二 if Nz(Me.原_退休费) = Me.原_退休费 Then Me.原_退休费 = 0 有 ...

  6. eclipse 启动不起来(不能创建VM)

    Specifying the Java virtual machine Here is a typical Eclipse command line: eclipse -vm c:\jdk1.4.2\ ...

  7. js Date 函数方法

    var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份(4位,1970-???? ...

  8. Selenium2+python自动化41-绕过验证码(add_cookie)

    前言 验证码这种问题是比较头疼的,对于验证码的处理,不要去想破解方法,这个验证码本来就是为了防止别人自动化登录的.如果你能破解,说明你们公司的验证码吗安全级别不高,那就需要提高级别了. 对于验证码,要 ...

  9. Nginx+Memcached+Tomcat集群配置实践(Sticky Session)

    准备工作 创建一个简单的web应用,名为session.其中有两个页面,分别如下所示: 页面login.jsp <%@ page language="java" conten ...

  10. CAS工作流程

    CAS3.0的工作流程: 0.app将用户转发到CAS处, 并将自己的url作为callback参数传给CAS. 1.CAS验证用户成功(authentication) 2.生成用户实体(princi ...