WinCE下,C#更改wince操作系统的时间

来源:互联网 发布:淘宝店铺导航条字体 编辑:程序博客网 时间:2024/05/16 00:58

最近有一个WINCE下的小项目,有要设置系统时间的功能

代码如下:

using System.Runtime.InteropServices;[DllImport("coredll.dll")]private static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);        [StructLayout(LayoutKind.Sequential)]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;}private void setTime(){try{// 自己获取到的时间, 如 DateTime.Now.Year等string ttstr = "2013-06-03-10-26-31";string remoteTime = ttstr.Substring(0, 4) + "-" + ttstr.Substring(5, 2) + "-" + ttstr.Substring(8, 2) + "-" + ttstr.Substring(11, 2) + "-" + ttstr.Substring(14, 2) + "-" + ttstr.Substring(17, 2) ; //DateTime.Parse( // ws.getTime();     //2013-06-03-10-26-31string[] str = remoteTime.Split('-');SYSTEMTIME systNew = new SYSTEMTIME();systNew.wDay = Convert.ToUInt16(str[2]);systNew.wMonth = Convert.ToUInt16(str[1]);systNew.wYear = Convert.ToUInt16(str[0]);systNew.wHour = Convert.ToUInt16(str[3]);systNew.wMinute = Convert.ToUInt16(str[4]);systNew.wSecond = Convert.ToUInt16(str[5]);SetLocalTime(ref systNew);}catch (Exception ex){MessageBox.Show(ex.Message);}}


原创粉丝点击