Set System Time In C#

If you want to change your system time through code then you can achieve it through kernel32.dll.

Kernel32.dll is a Windows kernel module. It is a 32-bit dynamic link library that is used in Windows operating systems. 

using System.Runtime.InteropServices;

A pointer to a SYSTEMTIME structure that contains the new system date and time.

[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME {
    public short wYear;
    public short wMonth;
    public short wDayOfWeek;
    public short wDay;
    public short wHour;
    public short wMinute;
    public short wSecond;
    public short wMilliseconds;
}
class Program {
    static void Main(string[] args) {
            SYSTEMTIME st = new SYSTEMTIME();
            st.wYear = 2022; // must be short
            st.wMonth = 03;
            st.wDay = 01;
            st.wHour = 19;
            st.wMinute = 04;
            st.wSecond = 00;
            SetSystemTime(ref st);
        }
        [DllImport("kernel32.dll", SetLastError = true)]
    public static extern bool SetSystemTime(ref SYSTEMTIME st);
}

SetSystemTime function Sets the current system time and date. The system time is expressed in Coordinated Universal Time (UTC).