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 ...
随机推荐
- 3D案例,导航,导航升级版
/*****************************百度钱包旋转变内容******************************/ <!DOCTYPE html> <htm ...
- 【转】C++的继承与多态:为什么需要虚函数
转自:http://www.educity.cn/zk/gjyy/201306271108011682.htm 多态性是面向对象设计语言的基本特征.仅仅是将数据和函数捆绑在一起,进行类的封装,使用一些 ...
- Oracle Outline总结
一.基本概述 Oracle Outline,中文也称为存储大纲,是最早的基于提示来控制SQL运行计划的机制.也是9i以及之前版本号唯一能够用来稳定和控制SQL运行计划的工具. outline是一个hi ...
- 路冉的JavaScript学习笔记-2015年2月5日
1.为Js原始值创建临时对象,并进行属性引用 var s="text"; s.len=4;//这里Js调用new String(s)的方法创建了一个临时对象,用来属性引用 cons ...
- Nginx/Apache图片缩略图技术
1,目的 2,使用方式 3,Nginx + Linux 缩略图实现 3.1,原理 3.2,nginx配置实现 3.3,例子 4,Apache + Windows缩略图实现 4.1,环境 4.2,原理 ...
- [React] React Fundamentals: Component Lifecycle - Updating
The React component lifecycle will allow you to update your components at runtime. This lesson will ...
- Android 软件开发之 PreferenceActivity 中的组件
1.PreferenceActivity 介绍 PreferenceActivity 继承ListActivity 它是以一个列表的形式在展现内容,它最主要的特点是添加Preference可以让控件的 ...
- Top 10 Questions about Java Exceptions--reference
reference from:http://www.programcreek.com/2013/10/top-10-questions-about-java-exceptions/ This arti ...
- asp.net下载的方法1
1. 首先新建一个用于进行下载处理的page页,如download.aspx,里面什么东西也没有. 2. 添加一个DownloadHandler类,它继承于IHttpHandler接口,可以用来自定义 ...
- Spring-data-redis操作redis cluster
Redis 3.X版本引入了集群的新特性,为了保证所开发系统的高可用性项目组决定引用Redis的集群特性.对于Redis数据访问的支持,目前主要有二种方式:一.以直接调用jedis来实现:二.使用sp ...