在Windows 7上使用C#设置系统时间

Mar*_*usM 1 c# windows-7

如何在Windows 7上使用C#以编程方式设置本地时间?

ale*_*oot 7

[StructLayout(LayoutKind.Sequential)]
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;
}

[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool SetSystemTime( [In] ref SYSTEMTIME st );

SYSTEMTIME st = new SYSTEMTIME();
st.wYear = 2003; // must be short 
st.wMonth = 5; 
st.wDay = 22;
st.wHour = 0;
st.wMinute = 0;
st.wSecond = 0;

SetSystemTime(ref st);
Run Code Online (Sandbox Code Playgroud)