两中方法:
1.可以用API来做:
[StructLayout (LayoutKind.Sequential)]
public 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 Miliseconds;
}
//api函数声明
[DllImport ("kernel32.dll", CharSet=CharSet.Ansi)]
public extern static bool SetSystemTime(ref SYSTEMTIME time);
private void button1_Click(object sender, System.EventArgs e)
{
//调用代码
SYSTEMTIME t = new SYSTEMTIME ();
t.Year = 2000;
t.Month = 1;
t.Day = 2;
t.Hour = 12-8; //这个函数使用的是0时区的时间,对于我们用+8时区的,时间要自己算一下.如要设12点,则为12-8
t.Minute = 5;
bool v = SetSystemTime(ref t);
Console.WriteLine(v.ToString());
}
2. VB.NET 特有的方法,很简单
Today=日期
TimeOfDay=时间
如何利用VB.NET修改系统时间
80酷酷网 80kuku.com