热心网友
回答时间:2024-04-29 21:41
自己写个操作系统
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();
}
}
}
---------------c#
收起