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 ...
随机推荐
- 使用sqlite3 有关tableview删除cell的问题
在root页面,想要删除tableviewcell,是有一定顺序的 首先要删除 数据库sqlite3 中的数据,然后删除数组中的数据,最后删除cell 一般我们知道,删除cell要在删除数组数据之后, ...
- mongdb使用场景
你期望一个更高的写负载 默认情况下,对比事务安全,MongoDB更关注高的插入速度.如果你需要加载大量低价值的业务数据,那么MongoDB将很适合你的用例.但是必须避免在要求高事务安全的情景下使用Mo ...
- Java immutable class
可变类:类的实例创立之后,还可以修改这个实例的内容. 比如创建一个3*3的矩阵,如果设立了set function,在main中可以用set更改对应位置元素的大小. 不可变类:就是类的实例一旦被建立, ...
- 简明网络I/O模型---同步异步阻塞非阻塞之惑
转自:http://www.jianshu.com/p/55eb83d60ab1 网络I/O模型 人多了,就会有问题.web刚出现的时候,光顾的人很少.近年来网络应用规模逐渐扩大,应用的架构也需要随之 ...
- MySQL约束
MySQL中约束保存在information_schema数据库的table_constraints中,可以通过该表查询约束信息: 常用5种约束: not null: 非空约束,指定某列不为空 uni ...
- DotNet Core 之旅(一)
1.下载安装 DotNetCore.1.0.0-SDK.Preview2-x64.exe 下载链接:https://www.microsoft.com/net/download ps:如果有vs201 ...
- jasper2
package jasper; import java.io.File;import java.io.FileOutputStream;import java.io.OutputStream;impo ...
- 将Excel,ppt和word转化为html
有些时候可能需要将Excel,ppt和word转化为html在页面上显示.我从网上查到一些代码,记录在这里以供需要的朋友参考 1.将word转化为html显示 //================== ...
- iOS--检测野指针
定位野指针除了使用Malloc Scribble(内存涂鸦)外,还可以使用僵尸对象.所谓的僵尸对象,就是将被释放的对象标记为僵尸,系统不会回收这些对象的内存,并让这些内存无法被重用,因而也就不会被覆写 ...
- IOS 高级开发 runtime(二)
二.移魂大法 使用runtime还可以交换两个函数.先贴上代码和执行结果. #import <Foundation/Foundation.h> @interface DZLPerson : ...