1. Change System Time
C # System. the DateTime class encapsulates the date and time, which is convenient for time conversion and processing, but I have not found any member in it that can be used to modify the system time. Friends who have used VC and VB may know that we can call Win32 API SetLocalTime to change the system time. It seems that C # can only do this. SetLocalTime requires a SYSTEMTIME structure pointer as a parameter, which is not difficult. We can quickly define this structure in C #, but the problem is, I also want to "enjoy ".. NET Framework System. what should I do if DateTime is convenient in time conversion and processing? You only need to do it yourself. Compile a member function for SYSTEMTIME in C # to convert the function to System. DateTime. See the following code:
First, I created a new C # file to facilitate future calls, put the SetLocalTime API in a class named Win32API, and put the class in my own namespace, avoid Name Conflict. In the future, I can add frequently-used APIs to this class and namespace to construct my own C # Win32 API function library J.
// Forproc_Win32.cs
// Declare common Win32 API functions and structures
Using System;
Using System. Runtime. InteropServices;
Namespace Farproc. Win32
{
/// <Summary>
///
/// </Summary>
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;