程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> winfrom 更改本地時間

winfrom 更改本地時間

編輯:C#入門知識

引用命名空間
using System.Runtime.InteropServices;     
  [DllImport("Kernel32.dll")]
        private static extern bool SetLocalTime(ref systimelp SystemTime);
        [StructLayout(LayoutKind.Sequential)]
        private struct systime
{
            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 SetSystemTime(DateTime date)
        {
            SYSTEMTIME lpTime = new SYSTEMTIME();
            lpTime.wYear = Convert.ToUInt16(date.Year);
            lpTime.wMonth = Convert.ToUInt16(date.Month);
            lpTime.wDayOfWeek = Convert.ToUInt16(date.DayOfWeek);
            lpTime.wDay = Convert.ToUInt16(date.Day);
            DateTime time = DateTime.Now;
            lpTime.wHour = Convert.ToUInt16(time.Hour);
            lpTime.wMinute = Convert.ToUInt16(time.Minute);
            lpTime.wSecond = Convert.ToUInt16(time.Second);
            lpTime.wMilliseconds = Convert.ToUInt16(time.Millisecond);
            SetLocalTime(ref lpTime);
        }
   public  void button1_Click(object sender, EventArgs e)
        {
            SetSystemTime(DateTime.Parse(shijian));}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved