PDA与服务器时间同步

ContractedBlock.gifExpandedBlockStart.gifCode
 1ContractedBlock.gifExpandedBlockStart.gif 定义系统时间#region 定义系统时间
 2        [StructLayout(LayoutKind.Sequential)]
 3        public struct SystemTime
 4ExpandedSubBlockStart.gifContractedSubBlock.gif        {
 5            public ushort wYear;
 6            public ushort wMonth;
 7            public ushort wDayOfWeek;
 8            public ushort wDay;
 9            public ushort wHour;
10            public ushort wMinute;
11            public ushort wSecond;
12            public ushort wMiliseconds;
13        }

14        #endregion

15
16ContractedBlock.gifExpandedBlockStart.gif        引用WIN32 API函数#region 引用WIN32 API函数
17        public class Win32
18ExpandedSubBlockStart.gifContractedSubBlock.gif        {
19            //引用dll文件(WIN API)
20            [DllImport("Coredll.dll")]
21            public static extern bool SetLocalTime(ref SystemTime sysTime);
22        }

23        #endregion

24
25ContractedBlock.gifExpandedBlockStart.gif        设置系统时间#region 设置系统时间
26ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
27        /// 设置系统时间
28        /// </summary>
29        /// <param name="time"></param>

30        public static void SetDateTime(DateTime time)
31ExpandedSubBlockStart.gifContractedSubBlock.gif        {
32            SystemTime sysTime = new SystemTime();
33
34            sysTime.wYear = Convert.ToUInt16(time.Year);
35            sysTime.wMonth = Convert.ToUInt16(time.Month);
36            sysTime.wDay = Convert.ToUInt16(time.Day);
37            sysTime.wDayOfWeek = Convert.ToUInt16(time.DayOfWeek);
38            sysTime.wHour = Convert.ToUInt16(time.Hour);
39            sysTime.wMinute = Convert.ToUInt16(time.Minute);
40            sysTime.wSecond = Convert.ToUInt16(time.Second);
41            sysTime.wMiliseconds = Convert.ToUInt16(time.Millisecond);
42
43            Win32.SetLocalTime(ref sysTime);
44        }

45        #endregion

 

现在只需调用SetDateTime(获取到服务器的时间),OK再也不用为PDA与服务器时间不同步而烦恼了。

转载于:https://www.cnblogs.com/sean886/archive/2009/06/05/Time.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值