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
posted @ 2009-03-17 14:15  木瓜脑袋  阅读(1335)  评论(0编辑  收藏  举报