try this:using System;
using System.Runtime.InteropServices;namespace ConsoleApplication20
{
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds; public DateTime ToDateTime()
{
return new DateTime(wYear, wMonth, wDay, wHour, wMinute, wSecond,
wMilliseconds);
}
} class Win32API
{
[DllImport("Kernel32.dll")]
public static extern bool SetSystemTime(ref SYSTEMTIME st);
[DllImport("Kernel32.dll")]
public static extern void GetSystemTime(out SYSTEMTIME st);
} class Class1
{
[STAThread]
static void Main(string[] args)
{
SYSTEMTIME st;
Win32API.GetSystemTime(out st); // gets current time
Console.WriteLine( st.ToDateTime().ToLocalTime().ToString() );
st.wMinute++; // Adjust minutes
if (!Win32API.SetSystemTime(ref st)) // sets system time
Console.WriteLine("An error occured setting the system time");
Win32API.GetSystemTime(out st); // gets current time
Console.WriteLine( st.ToDateTime().ToLocalTime().ToString() );
Console.ReadLine();
}
}
}
using System.Runtime.InteropServices;namespace ConsoleApplication20
{
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds; public DateTime ToDateTime()
{
return new DateTime(wYear, wMonth, wDay, wHour, wMinute, wSecond,
wMilliseconds);
}
} class Win32API
{
[DllImport("Kernel32.dll")]
public static extern bool SetSystemTime(ref SYSTEMTIME st);
[DllImport("Kernel32.dll")]
public static extern void GetSystemTime(out SYSTEMTIME st);
} class Class1
{
[STAThread]
static void Main(string[] args)
{
SYSTEMTIME st;
Win32API.GetSystemTime(out st); // gets current time
Console.WriteLine( st.ToDateTime().ToLocalTime().ToString() );
st.wMinute++; // Adjust minutes
if (!Win32API.SetSystemTime(ref st)) // sets system time
Console.WriteLine("An error occured setting the system time");
Win32API.GetSystemTime(out st); // gets current time
Console.WriteLine( st.ToDateTime().ToLocalTime().ToString() );
Console.ReadLine();
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货