首页  编辑  

读取和设置系统时间

Tags: /C#/API调用/   Date Created:

using System . Runtime . InteropServices;

[ StructLayout ( LayoutKind . Sequential)]

public class SystemTime

{

    public ushort year;

    public ushort month;

    public ushort dayOfWeek;

    public ushort day;

    public ushort hour;

    public ushort minute;

    public ushort second;

    public ushort milliseconds;

}

[ DllImport ( "Kernel32.dll" )]

public static extern void GetSystemTime([ In , Out ] SystemTime st);

[ DllImport ( "Kernel32.dll" )]

public static extern bool SetSystemTime([ In , Out ] SystemTime st);

SystemTime vSystemTime = new SystemTime ();

GetSystemTime(vSystemTime);

vSystemTime . year += 1 ;

SetSystemTime(vSystemTime);