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

    通过调用系统API设置系统时间。

    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;

    namespace talefox.ShareLib

    {
        public class SystemDateTime
        {
            [DllImport("kernel32.dll")]
            private static extern bool SetLocalTime(ref SYSTEMTIME time);

            [StructLayout(LayoutKind.Sequential)]
            private struct SYSTEMTIME
            {
                public short year;
                public short month;
                public short dayOfWeek;
                public short day;
                public short hour;
                public short minute;
                public short second;
                public short milliseconds;
            }
            /// <summary>
            /// 设置系统时间
            /// </summary>
            /// <param name="dt"></param>
            public static void SetDate(DateTime dt)
            {
                SYSTEMTIME st;

                st.year = (short)dt.Year;
                st.month = (short)dt.Month;
                st.dayOfWeek = (short)dt.DayOfWeek;
                st.day = (short)dt.Day;
                st.hour = (short)dt.Hour;
                st.minute = (short)dt.Minute;
                st.second = (short)dt.Second;
                st.milliseconds = (short)dt.Millisecond;

                SetLocalTime(ref st);
            }
        }
    }

  • 相关阅读:
    strace命令的使用
    部署软件RDMA的步骤
    centos7上安装iptables
    在Linux中的.iso文件的处理方法
    centos7关闭自动锁屏
    SSH配置优化和慢的解决方法
    sort排序和uniq统计命令
    ansible的携带密码访问
    fabric入门
    防火墙设置本机端口转发
  • 原文地址:https://www.cnblogs.com/talefox/p/1322548.html
Copyright © 2011-2022 走看看