c# 获取北京时间更新本地计算机
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# 获取北京时间更新本地计算机的更多相关文章
- C#获取北京时间与设置系统时间
获取北京时间 public static DateTime GetBeijingTime() { DateTime dt; // 返回国际标准时间 // 只使用 timeServers 的 IP 地址 ...
- atitit.获取北京时间CST 功能api总结 O7
atitit.获取北京时间CST 功能api总结 O7 1. 获取cst时间(北京时间)两布:1.抓取url timtstamp >>format 到cst 1 2. 设置本机时间 se ...
- python获取网络时间和本地时间
今天我们来看一下如何用python获取网络时间和本地时间,直接上代码吧,代码中都有注释. python获取网络时间 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
- C#获取获取北京时间多种方法
#region 获取网络时间 ///<summary> /// 获取中国国家授时中心网络服务器时间发布的当前时间 ///</summary> ///<returns> ...
- C# 获取北京时间 (根据纪元时间(1970/1/1)转换为DateTime)
根据纪元时间(1970/1/1)转换为DateTime WebClient wc = new WebClient(); s= wc.DownloadString("http://api.ti ...
- delphi 获取北京时间(使用XMLHTTP获取百度的时间,WebBrowser获取www.timedate.cn的时间)
方法一: uses ComObj, DateUtils; function GetInternetTime: string; var XmlHttp: OleVariant; datetxt: str ...
- Delphi 获取北京时间(通过百度和timedate网站)
方法一: uses ComObj, DateUtils; function GetInternetTime: string; var XmlHttp: OleVariant; datetxt: str ...
- js 获取北京时间
<SCRIPT LANGUAGE = "JavaScript"> var xmlhttp = new ActiveXObject("MSXML2.XMLHTT ...
- Unity 获取服务器时间 HTTP请求方式
在写每日签到的时候,我居然使用的是本地时间...被项目经理笑哭了...., 如果你在写单机游戏,没有游戏服务器,但又不想使用本地时间,就可以采用下面方法. 方法总结: 1. 使用HTTP请求获取服务器 ...
随机推荐
- 委托、多播委托、泛型委托Func,Action,Predicate,ExpressionTree
当试图通过一个事件触发多个方法,抽象出泛型行为的时候,或许可以考虑使用委托. 通过委托构造函数或委托变量把方法赋值给委托 private delegate double DiscountDel ...
- Eclipse配置mybatis-generator插件的2种方法
原文:https://blog.csdn.net/u012825737/article/details/79117540 最近在做一个Mybatis的项目,学习到了一个插件mybatis-genera ...
- SQL 条件 判断 select case as
" then "返回的数据1" " then "返回的数据2" else "返回的其他数据" end as 新的列名 f ...
- UITextView in iOS7 doesn't scroll
UITextView in iOS7 has been really weird. As you type and are entering the last line of your UITextV ...
- mysql数据库字符集初步理解
1.MySQL(4.1以后版本) 服务器中有六个关键位置使用了字符集的概念,他们是: 1.client 2.connection 3.database 4.results 5.server 6.sys ...
- [翻译] ADPopupView 触摸弹出视窗
ADPopupView 触摸弹出视窗 https://github.com/Antondomashnev/ADPopupView ADPopupView is an iOS drop-in class ...
- 文件内容操作篇clearerr fclose fdopen feof fflush fgetc fgets fileno fopen fputc fputs fread freopen fseek ftell fwrite getc getchar gets
clearerr(清除文件流的错误旗标) 相关函数 feof 表头文件 #include<stdio.h> 定义函数 void clearerr(FILE * stream); 函数说明 ...
- 使用supervisor过程的坑
1.安装:由于使用的是公司的虚拟机,所以使用pip install supervisor的过程遇到很多权限问题. 中间尝试使用sudo pip install supervisor的方式安装,但是使用 ...
- 俄罗斯水手 [C#] 对List<T>取交集、连集及差集
※本文使用int為例,若為使用自訂之DataModel,需實作IEquatable<T>介面才能使用 1. 取交集 (A和B都有) List A : { 1 , 2 , 3 , 5 , ...
- Design Your Own Protocol In Five Minutes
https://mayaposch.wordpress.com/2011/10/03/design-your-own-protocol-in-five-minutes ---------------- ...