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;
        }
  • 相关阅读:
    001_jdk配置
    mysql(5.7)安装教程
    mysql(5.6)安装教程
    外网发布
    蓝桥 历届试题 分考场
    蓝桥 历届试题 合根植物
    Codeforces Round #650 (Div. 3) D : Task On The Board
    HDU 3336 Count the string
    leetcode [238. 除自身以外数组的乘积]
    leetcode [837. 新21点]
  • 原文地址:https://www.cnblogs.com/lhlong/p/6622300.html
Copyright © 2011-2022 走看看