修改系统时间

修改系统时间:
  class  APP
    
{
        [StructLayout(LayoutKind.Sequential)]
        
public struct SystemTime
        
{
            
public ushort wYear;
            
public ushort wMonth;
            
public ushort wDayOfWeek;
            
public ushort wDay;
            
public ushort wHour;
            
public ushort wMinute;
            
public ushort wSecond;
            
public ushort wMiliseconds;
        }


        [DllImport(
"kernel32")]
        
public static extern Int32 SetSystemTime(ref SystemTime time);
 
        
public static void SetDate(DateTime dt)
        
{
            SystemTime st;

            st.wYear 
= (ushort)dt.Year;
            st.wMonth 
= (ushort)dt.Month;
            st.wDayOfWeek 
= (ushort)dt.DayOfWeek;
            st.wDay 
= (ushort)dt.Day;
            st.wHour 
= (ushort)dt.Hour;
            st.wMinute 
= (ushort)dt.Minute;
            st.wSecond 
= (ushort)dt.Second;
            st.wMiliseconds 
= (ushort)dt.Millisecond;

            SetSystemTime(
ref st);
        }

    }

你可能感兴趣的:(系统时间)