WinCE.NET中设置系统日期时间

 using System;
 using System.Runtime.InteropServices;

 class SysDateTime
 {
     private 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 wMilliseconds;
     }
 
     [DllImport("Coredll.dll")]
     private static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);
 
     public static void SetDateTime(DateTime dt)
     {
         #region Codes==========================================================

         SYSTEMTIME sysTime = new SYSTEMTIME();
         
         sysTime.wYear = Convert.ToUInt16(dt.Year);
         sysTime.wMonth = Convert.ToUInt16(dt.Month);
         sysTime.wDay = Convert.ToUInt16(dt.Day);
         sysTime.wDayOfWeek = Convert.ToUInt16(dt.DayOfWeek);
         sysTime.wHour = Convert.ToUInt16(dt.Hour);
        sysTime.wMinute = Convert.ToUInt16(dt.Minute);
        sysTime.wSecond = Convert.ToUInt16(dt.Second);
        sysTime.wMilliseconds = Convert.ToUInt16(dt.Millisecond);
 
         SetLocalTime(ref sysTime);
 
         #endregion
    }
 } // class

你可能感兴趣的:(WinCE)