try to use SetSystemTime[StructLayout(LayoutKind.Sequential)] public class SYSTEMTIME { public Int16 wYear; public Int16 wMonth; public Int16 wDayOfWeek; public Int16 wDay; public Int16 wHour; public Int16 wMinute; public Int16 wSecond; public Int16 wMilliseconds; } [DllImport("kernel32.dll")] public static extern bool SetSystemTime([In, MarshalAs(UnmanagedType.LPStruct)]SYSTEMTIME lpSystemTime); [DllImport("kernel32.dll")] public static extern void GetSystemTime([Out, MarshalAs(UnmanagedType.LPStruct)]SYSTEMTIME lpSystemTime);
谢谢 saucer(思归, MS .NET MVP) ,原来要先GetSystemTime才有效呀 :) SYSTEMTIME s=new SYSTEMTIME(); LibWrap.GetSystemTime(s); //Console.WriteLine("Current SystemTime is {0} ",s.wYear); s.wYear=1999; s.wMonth=10; s.wHour=10; LibWrap.SetSystemTime(s);
public class SYSTEMTIME {
public Int16 wYear;
public Int16 wMonth;
public Int16 wDayOfWeek;
public Int16 wDay;
public Int16 wHour;
public Int16 wMinute;
public Int16 wSecond;
public Int16 wMilliseconds;
} [DllImport("kernel32.dll")]
public static extern bool SetSystemTime([In,
MarshalAs(UnmanagedType.LPStruct)]SYSTEMTIME lpSystemTime);
[DllImport("kernel32.dll")]
public static extern void GetSystemTime([Out,
MarshalAs(UnmanagedType.LPStruct)]SYSTEMTIME lpSystemTime);
SYSTEMTIME s=new SYSTEMTIME();
LibWrap.GetSystemTime(s);
//Console.WriteLine("Current SystemTime is {0} ",s.wYear);
s.wYear=1999;
s.wMonth=10;
s.wHour=10;
LibWrap.SetSystemTime(s);