Chinaunix首页 | 论坛 | 博客
  • 博客访问: 370235
  • 博文数量: 132
  • 博客积分: 3066
  • 博客等级: 中校
  • 技术积分: 781
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-14 16:19
文章分类

全部博文(132)

文章存档

2012年(1)

2010年(50)

2009年(81)

我的朋友

分类: C/C++

2009-06-15 18:35:24

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
///////////////////////////////////////////////////////////////////////////////
 
 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("coredll")]
                public   static   extern   bool   SetSystemTime(ref   SystemTime   sysTime);         //设置系统时间

SystemTime   time   =   new   SystemTime();
                                time.wYear   =   2007;
                                time.wMonth   =   9;
                                time.wDay   =   30;
                                time.wHour   =   16;
                                time.wMinute   =   0;
                                time.wSecond   =   0;
                                SetSystemTime(ref   time);
文章出处:
 
阅读(599) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~