public static Task<int> Set(DateTimeOffset datetime) { SYSTEMTIME systime = new SYSTEMTIME(); systime.wYear = (ushort)datetime.Year; systime.wMonth = (ushort)datetime.Month; systime.wDay = (ushort)datetime.Day; systime.wDayOfWeek = (ushort)datetime.DayOfWeek; systime.wHour = (ushort)datetime.Hour; systime.wMinute = (ushort)datetime.Minute; systime.wSecond = (ushort)datetime.Second; systime.wMilliseconds = (ushort)datetime.Millisecond; int result = SetSystemTime(ref systime); if (result == 0) { result = SystemDateTime.GetLastError(); string errorMessage = new Win32Exception(result).Message; throw new Exception(errorMessage); } return Task.FromResult(result); }
private extern static int SetSystemTime(ref SYSTEMTIME lpSystemTime);
private extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);
private extern static int SetSystemTime(ref SYSTEMTIME lpSystemTime);
private extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);