修改系统时间功能的实现
来源:互联网 发布:游戏配音软件 编辑:程序博客网 时间:2024/05/06 11:11
using System.Runtime.InteropServices; //System.Runtime.InteropServices一般用到其中的DllImport,它用来调用windows中一些DLL的函数(Windows API),或调用自己用c++写的DLL中的函数.
#region ComputerTime
[StructLayout(LayoutKind.Sequential)]
public struct SystemTime
{
public ushort wYear;//ushort 为无符号16位整数
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMiliseconds;
}
public class Win32
{
[DllImport("Kernel32.dll ")]//参看:http://hi.baidu.com/ja86/blog/item/011c6522455f88fad7cae2ce.html
public static extern bool SetSystemTime(ref SystemTime SysTime);//SetSystemTime设置格林威治时间,比北京时间晚8小时,需要调整wHour。
[DllImport("Kernel32.dll ")]
public static extern void GetSystemTime(ref SystemTime SysTime);
}
#endregion
#region 时间同步
/// <summary>
/// 设置与服务器同步时间
/// </summary>
public void SynchronousTime(string strdt)
{
try
{
#region 更改计算机时间
SystemTime sysTime = new SystemTime();
DateTime ServerTime = Convert.ToDateTime(strdt);
sysTime.wYear = Convert.ToUInt16(ServerTime.Year);
sysTime.wMonth = Convert.ToUInt16(ServerTime.Month);
//处置北京时间
int nBeijingHour = ServerTime.Hour - 8;
if (nBeijingHour <= 0)
{
nBeijingHour += 24;
sysTime.wDay = Convert.ToUInt16(ServerTime.Day - 1);
sysTime.wDayOfWeek = Convert.ToUInt16(ServerTime.DayOfWeek - 1);
}
else
{
sysTime.wDay = Convert.ToUInt16(ServerTime.Day);
sysTime.wDayOfWeek = Convert.ToUInt16(ServerTime.DayOfWeek);
}
sysTime.wHour = Convert.ToUInt16(nBeijingHour);
sysTime.wMinute = Convert.ToUInt16(ServerTime.Minute);
sysTime.wSecond = Convert.ToUInt16(ServerTime.Second);
sysTime.wMiliseconds = Convert.ToUInt16(ServerTime.Millisecond);
Win32.SetSystemTime(ref sysTime);
#endregion
}
catch
{
//产生错误则不引发异常。
}
}
#endregion
- 修改系统时间功能的实现
- 修改系统的时间
- (android之系统)android OTA 的功能实现和修改
- 修改linux系统的时间
- 修改linux系统的时间
- 修改ubuntu系统的时间
- 修改ubuntu系统的时间
- 修改Linux的系统时间
- 修改debian的系统时间
- 修改ubuntu系统的时间
- 通过HOOK系统的API接口实现对API功能的修改
- 汇编实现的简单的通讯录系统,有插入,修改,删除,打印,查找功能
- File 得到系统的修改时间
- 修改系统本地时间的 API
- c#修改系统时间的方法
- c#修改系统时间的方法
- VB.NET中修改系统的时间
- 如何修改Linux的系统时间
- 给年轻程序员的建议
- H.264句法和语法总结(十一)宏块层预测句法
- 成人如何学好英语
- H.264句法和语法总结(十二)子宏块预测句法
- 竞业禁止
- 修改系统时间功能的实现
- H.264句法和语法总结(十三)残差句法
- SD/MMC/SDIO 概念区分概要
- H.264句法和语法总结(十四)CAVLC 残差句法
- Linux 入门常用命令 — 文件的复制、删除和移动
- 滤波器的时域理解
- 你只管低着头上山,暂时不要向山上看
- 将jar文件与dex文件的转换
- strut2 单文件上传