您可能需要使用Win32 API来执行此操作,因为我非常确定框架中没有任何内容:
[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(ref SYSTEMTIME theDateTime );
Run Code Online (Sandbox Code Playgroud)
在PInvoke.net上有一个更完整的例子,代码有点密集,但是一个简单易懂的阅读和理解的摘录是这样的:
SYSTEMTIME st = new SYSTEMTIME();
GetSystemTime(ref st);
// Adds one hour to the time that was retrieved from GetSystemTime
st.wHour = (ushort)(st.wHour + 1 % 24);
var result = SetSystemTime(ref st);
if (result == false)
{
// Something went wrong
}
else
{
// The time will now be 1hr later than it was previously
}
Run Code Online (Sandbox Code Playgroud)
相关的特定Win32 API是SetSystemTime,GetSystemTime和SYSTEMTIME结构.