不知道爲什麼它不爲你工作。以下代碼將時間設置爲今日下午4:12 UTC的時間。 (爲我工作)
public class Program
{
public struct SystemTime
{
public ushort Year;
public ushort Month;
public ushort DayOfWeek;
public ushort Day;
public ushort Hour;
public ushort Minute;
public ushort Second;
public ushort Millisecond;
};
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
public extern static bool Win32SetSystemTime(ref SystemTime st);
public static void Main(string[] args)
{
SystemTime st = new SystemTime
{
Year = 2010, Month = 10, Day = 18, Hour = 16, Minute = 12, DayOfWeek = 1
};
}
}
按照docs:
調用進程必須有SE_SYSTEMTIME_NAME特權。該特權在默認情況下被禁用。 SetSystemTime函數在更改系統時間之前啓用SE_SYSTEMTIME_NAME特權,並在返回之前禁用特權。有關更多信息,請參閱使用特權運行。
所以看起來這應該不是一個問題。
是。它改變時間,但不接受時區... – 2012-04-27 18:00:00