不知道为什么它不为你工作。以下代码将时间设置为今日下午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