C#中如何更改当前时间
来源:百度知道 编辑:UC知道 时间:2024/05/21 12:06:15
using System.Runtime.InteropServices;
//imports SetLocalTime function from kernel32.dll
[DllImport("kernel32.dll", SetLastError=true)]
public static extern int SetLocalTime (ref SystemTime lpSystemTime);
//struct for date/time apis
public struct SystemTime
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
// And then set up a structure with the required properties and call the api from code:
SystemTime systNew = new SystemTime();
// 设置属性
systNew.wDay = 1;
systNew.wMonth = 1;
systNew.wYear = 2004;
systNew.wHour = 9;
systNew.wMinute = 0;
systNew.wSecond = 0;
// 调用API,更新系统时间
SetLocalTime(ref systNew);
创建对象 DateTime dt = new DateTime();
dt实例中有好多方法都