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);
      }

     }


     

  • 相关阅读:
    搜索专题
    KMP专题
    CSU 1326: The contest(分组背包)
    强连通专题
    MST:Bad Cowtractors(POJ 2377)
    MST:Agri-Net(POJ 1258)
    ShortestPath:Layout(POJ 3169)(差分约束的应用)
    MST:Conscription(POJ 3723)
    MST:Roadblocks(POJ 3255)
    DP:Space Elevator(POJ 2392)
  • 原文地址:https://www.cnblogs.com/kimi/p/929908.html
Copyright © 2011-2022 走看看