zoukankan      html  css  js  c++  java
  • 设置系统时间

        /// <summary>
        /// 设置系统时间
        /// </summary>
        public class SetSTime
        {
            [DllImport("Kernel32.dll")]
            public static extern bool SetSystemTime(ref SystemTime sysTime);
            [DllImport("Kernel32.dll")]
            public static extern void GetSystemTime(ref SystemTime sysTime);
    
    
            /// <summary>
            /// 设置系统时间方法
            /// </summary>
            /// <param name="dt"></param>
            public static void SetSysTime(DateTime dt)
            {
                //不知道什么原因,必须先加八个小时,才能是准确时间。估计是时区问题
                DateTime dateTimePicker1 = dt.AddHours(-8);
    
                SystemTime MySystemTime = new SystemTime();
                MySystemTime.vYear = (ushort)dateTimePicker1.Year;
                MySystemTime.vMonth = (ushort)dateTimePicker1.Month;
                MySystemTime.vDay = (ushort)dateTimePicker1.Day;
                MySystemTime.vHour = (ushort)dateTimePicker1.Hour;
                MySystemTime.vMinute = (ushort)dateTimePicker1.Minute;
                MySystemTime.vSecond = (ushort)dateTimePicker1.Second;
    
                try
                {
    
                    SetSTime.SetSystemTime(ref MySystemTime);
    
                    SystemTime st2 = new SystemTime();
                    SetSTime.GetSystemTime(ref st2);
                }
                catch (Exception)
                {
    
                    throw;
                }
    
            }
        }
    
        public struct SystemTime
        {
            public ushort vYear;
            public ushort vMonth;
            public ushort vDayOfWeek;
            public ushort vDay;
            public ushort vHour;
            public ushort vMinute;
            public ushort vSecond;
            public ushort vMiliseconds;
        }
  • 相关阅读:
    高一下期末考试划水记
    BZOJ 1053
    积性函数与狄利克雷卷积(未完待更)
    Contest Hunter 3101
    POJ2689
    3.17爆零赛
    全概率公式
    矩阵快速幂
    模板练习
    _rqy's Code Style for OI
  • 原文地址:https://www.cnblogs.com/lhlong/p/6622300.html
Copyright © 2011-2022 走看看