C#修改电脑时间

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace settime
{
     class Program
    {
         public  struct SystemTime
        {
             public  short wYear;
             public  short wMonth;
             public  short wDayOfWeek;
             public  short wDay;
             public  short wHour;
             public  short wMinute;
             public  short wSecond;
             public  short wMilliseconds;
        }

        [DllImport( " kernel32.dll ", SetLastError =  true)]
         public  static  extern  int SetLocalTime( ref SystemTime lpSystemTime);

         static  void Main( string[] args)
        {
            DateTime newDate = DateTime.Now.AddDays( 1);
            SystemTime sysNew =  new SystemTime();
            sysNew.wDay = ( short)newDate.Day;
            sysNew.wMonth = ( short)newDate.Month;
            sysNew.wYear = ( short)newDate.Year;
            sysNew.wHour =  8;
            sysNew.wMinute =  59;
            sysNew.wSecond =  55;
            SetLocalTime( ref sysNew);
        }
    }
}

你可能感兴趣的:(C#)