zoukankan      html  css  js  c++  java
  • c# 修改系统本地时间

    /// <summary>
     ///系统时间类
     /// </summary>
     [ StructLayout( LayoutKind.Sequential )]
     public class SystemTime
     {
      public ushort year;
      public ushort month;
      public ushort dayofweek;
      public ushort day;
      public ushort hour;
      public ushort minute;
      public ushort second;
      public ushort milliseconds;
     }

     /// <summary>
     /// Windows API方法
     /// </summary>
     public class WinAPI
     {
      [ DllImport( "Kernel32.dll" )]
      private static extern Boolean SetSystemTime([In,Out] SystemTime st);

      /// <summary>
      /// 设置系统时间
      /// </summary>
      /// <param name="newdatetime">新时间</param>
      /// <returns></returns>
      public static bool SetSysTime(DateTime newdatetime)
      {
       SystemTime st = new SystemTime();
       st.year    = Convert.ToUInt16(newdatetime.Year);
       st.month   = Convert.ToUInt16(newdatetime.Month);
       st.day    = Convert.ToUInt16(newdatetime.Day);
       st.dayofweek  = Convert.ToUInt16(newdatetime.DayOfWeek);
       st.hour    = Convert.ToUInt16(newdatetime.Hour - TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2001,09,01)).Hours);
       st.minute   = Convert.ToUInt16(newdatetime.Minute);
       st.second   = Convert.ToUInt16(newdatetime.Second);
       st.milliseconds  = Convert.ToUInt16(newdatetime.Millisecond);
       return SetSystemTime(st);
      }

     }


     

  • 相关阅读:
    金额相关的测试用例
    Python练习题--持续更新
    Python基础--函数
    Python基础--文件操作和集合
    Python基础--数据类型
    Python基础--字典
    分布式理论(七)—— 一致性协议之 ZAB
    分布式理论(六)—— Raft 算法
    分布式理论(五)—— 一致性算法 Paxos
    分布式理论(四)—— 一致性协议之 3PC
  • 原文地址:https://www.cnblogs.com/kimi/p/929908.html
Copyright © 2011-2022 走看看