本人想做个一个定时关机,用DateTime获取了日期...系统时间格式:
 年/月/日   
 时/分/秒设定时间格式:
 年/月/日   
 时/分/秒下面想做设定时间减去系统时间的秒数,给个理论也可以..
谢谢.

解决方案 »

  1.   

    用下面这种方法:
    C#调用API实现的关机
      

  2.   

    很简单,几行代码就交工了.
    Visual C#设计多功能关机程序
      

  3.   

    Process proc = new Process(); 
    proc.StartInfo.FileName = "cmd.exe"; 
    proc.StartInfo.UseShellExecute = false; 
    proc.StartInfo.RedirectStandardError = true; 
    proc.StartInfo.RedirectStandardInput = true; 
    proc.StartInfo.CreateNoWindow = true; 
    proc.StartInfo.RedirectStandardOutput = true; 
    proc.Start(); 
    string commandLine = String.Empty; 
    switch (option) 

          case Program.OptionType.isCancel: 
                  commandLine += @"shutdown /a"; 
                  break; 
          case Program.OptionType.isLogoff: 
                  commandLine += @"shutdown /f /l /t" + BLANK + interval; 
                  break; 
          case Program.OptionType.isRestart: 
                  commandLine += @"shutdown /f /r /t" + BLANK + interval; 
                  break; 
          case Program.OptionType.isShutdown: 
                  commandLine += @"shutdown /f /s /t" + BLANK + interval; 
                  break; 
          } 
          proc.StandardInput.WriteLine(commandLine); 
    或  [DllImport("user32.dll")] 
            static extern bool ExitWindowsEx(ExitWindows uFlags, ShutdownReason dwReason); 
    http://topic.csdn.net/u/20090730/23/835694dd-ea4a-4651-8d78-5bf7cec57df4.html
      

  4.   

    计算两个时间相差的秒数,JJWW
      

  5.   

    DateTime dt = DateTime.Parse("2010-03-01 12:00:00");
    TimeSpan ts = dt - DateTime.Now;
    MessageBox.Show(ts.TotalSeconds.ToString());
      

  6.   

    for(;;){
    if (DateTime.Now >= ShutDownTime)
    {
       ShowDownComputer();  
    }
    }