view plaincopy to clipboardprint?
///调用API
[DllImport("kernel32.dll", SetLastError = true)]
public static extern int SetLocalTime(ref SystemTime lpSystemTime);
/// 定义结构
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;
}
/// 调用
SystemTime systNew = new SystemTime();
// 设置属性
systNew.wDay =short.Parse( DateTime.Now.Day.ToString());
systNew.wMonth = short.Parse( DateTime.Now.Month.ToString());
systNew.wYear = 2004;
systNew.wHour = short.Parse(DateTime.Now.Hour.ToString());
systNew.wMinute = short.Parse( DateTime.Now.Minute.ToString());
systNew.wSecond = short.Parse( DateTime.Now.Second.ToString());
// 调用API,更新系统时间
SetLocalTime(ref systNew);