An easy way to syncTime using C#
/*
* Created by SharpDevelop.
* User: Administrator
* Date: 2013/10/23
* Time: 8:57
* author zibet
*/
using System;
using System.Net;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace SyncTime
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
[StructLayout(LayoutKind.Sequential)]
public struct SystemTime
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMiliseconds;
}
public MainForm() {
InitializeComponent();
}
[DllImport("Kernel32.dll")]
public static extern bool SetLocalTime(ref SystemTime sysTime);
[DllImport("Kernel32.dll")]
public static extern void GetLocalTime(ref SystemTime localTime);
private DateTime getIntetime(){
return DateTime.Parse(WebRequest.Create("http://www.baidu.com/").GetResponse().Headers.Get("Date"));
}
void MainFormLoad(object sender, EventArgs e)
{
SystemTime st = new SystemTime();
DateTime BJTime = getIntetime();
st.wYear = Convert.ToUInt16(BJTime.Year);
st.wMonth = Convert.ToUInt16(BJTime.Month);
st.wDay = Convert.ToUInt16(BJTime.Day);
st.wHour = Convert.ToUInt16(BJTime.Hour);
st.wMinute = Convert.ToUInt16(BJTime.Minute);
st.wSecond = Convert.ToUInt16(BJTime.Second);
if (!SetLocalTime(ref st)) {
MessageBox.Show("Sync failed T-T");
return;
}
MessageBox.Show("Sync done!"); }
}
}
An easy way to syncTime using C#的更多相关文章
- 【转】Windows下使用libsvm中的grid.py和easy.py进行参数调优
libsvm中有进行参数调优的工具grid.py和easy.py可以使用,这些工具可以帮助我们选择更好的参数,减少自己参数选优带来的烦扰. 所需工具:libsvm.gnuplot 本机环境:Windo ...
- Struts2 easy UI插件
一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...
- Easy UI常用插件使用
一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...
- UVA-11991 Easy Problem from Rujia Liu?
Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...
- CodeForces462 A. Appleman and Easy Task
A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input sta ...
- easy ui插件
简介: easy UI是类似于jQuery UI的插件库 注意:多脚本同时使用时,注意脚本冲突问题. 常用插件: 1.tree插件(tree插件实现动态树形菜单) 2.datagrid插件(datag ...
- 用TPP开启TDD的easy模式
Test-Drived Development 测试驱动开发三步曲:写一个失败的测试用例->编写生产代码通过这个测试用例(transformation)->重构(refactor).重构是 ...
- Easy Sysprep更新日志-skyfree大神
Easy Sysprep更新日志: Skyfree 发表于 2016-1-22 13:55:55 https://www.itsk.com/forum.php?mod=viewthread&t ...
- [官方软件] Easy Sysprep v4.3.29.602 【系统封装部署利器】(2016.01.22)--skyfree大神
[官方软件] Easy Sysprep v4.3.29.602 [系统封装部署利器](2016.01.22) Skyfree 发表于 2016-1-22 13:55:55 https://www.it ...
随机推荐
- IOS-Archiver文件归档(2)
Archiver是持久化数据的一种方式,他跟 Plist的差别在于他能持久化自己定义对象.但他没Plist那么方便. Archiver默认能持久化的数据有NSNumber,NSArray,NSDict ...
- java中synchronized使用方法
synchronized的一个简单样例 public class TextThread { /** * @param args */ public static void main(String[ ...
- PagerSlidingTabStrip
https://github.com/jpardogo/PagerSlidingTabStrip
- mongodb的地理位置索引
mongoDB支持二维空间索引,使用空间索引,mongoDB支持一种特殊查询,如某地图网站上可以查找离你最近的咖啡厅,银行等信息.这个使用mongoDB的空间索引结合特殊的查询方法很容易实现.前提条件 ...
- CentOS开发环境LAMP搭建
CentOS开发环境搭建 -------------------------------------------------------------------------准备工作---------- ...
- velocity-字母序号 list
版权声明:本文为博主原创文章,未经博主允许不得转载. [需求] 遍历一个list,同时需要在每个item前面显示字母序号,例如A,B,C,D [代码] #set($zimu = ["A&qu ...
- sendStickyBroadcast和sendStickyOrderedBroadcast
sendStickyBroadcast和sendStickyOrderedBroadcast发出的广播会一直滞留(等待),以便有人注册这则广播消息后能尽快的收到这条广播.其他功能与sendBroadc ...
- Bluetooth in Android 4.2 and 4.3(三):Enable Bluetooth
以下是基于Android 4.2代码,对Bluetooth BR/EDR Enable process的分析.BluetoothAdapter类代表的是local device Bluetooth a ...
- eclipse 中修改 M2_REPO的值--转载
从eclipse中增加了maven2的插件之后,maven默认的本地库的路径是${user}/.m2/repository/下,一般windows用户的操作系统都安装在C盘,所以这个目录 下的jar包 ...
- 下载好一个android软件之后,怎样自动提示安装?
最近在做毕设,里面牵涉到版本更新,当有新版本时可以下载新版本,下载完成之后提示安装.那么怎么实现下载完成之后提示安装呢? 直接上代码吧: File mFile = new File(Environme ...