本文介绍了无法设置新的系统日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法更改systemdate,任何想法?

I cant change the systemdate, any ideas?

public struct Data
   {
     public ushort Year;
     public ushort Day;
     public ushort Month;
     public ushort Hour;
     public ushort Minute;
     public ushort Second;
     public ushort Millisecond;
     public ushort DayOfWeek;

   }
   class smth
        {
            [DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)]
            public extern static void Win32GetSystemTime(ref Data sysTime);
       [DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
       public extern static bool wSetSystemTime(ref Data sysTime);
   }

       public Form1()
       {
           InitializeComponent();
       }

       private void Form1_Load(object sender, EventArgs e)
       {

       }

       private void button1_Click(object sender, EventArgs e)
       {
           Data modifica = new Data();
           smth n = new smth();
           modifica.Day = (ushort) (ushort)dateTimePicker1.Value.Day;
           modifica.luna=(ushort) dateTimePicker1.Value.Month;
           modifica.an = (ushort)dateTimePicker1.Value.Year;
           MessageBox.Show(dateTimePicker1.Value.ToString());
          if( smth.wSetSystemTime(ref modifica))
              throw new System.ComponentModel.Win32Exception();
       }

推荐答案


这篇关于无法设置新的系统日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 01:30