private extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);
private 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;
}
private void GetTime() {
// Получим системное время
SYSTEMTIME st = new SYSTEMTIME();
GetSystemTime(ref st);
DateTime dt = DateTime.UtcNow.ToLocalTime();
// Выводим сообщение
MessageBox.Show("Текущее время: " + st.wHour.ToString() + ":" +
st.wMinute.ToString());
}
private void SetTime() {
// Сначала получим системное время
SYSTEMTIME st = new SYSTEMTIME();
GetSystemTime(ref st);
// А теперь прибавим один час
st.wHour = (ushort)(st.wHour + 1 % 24);
SetSystemTime(ref st);
MessageBox.Show("Новое время: " + st.wHour.ToString() + ":" +
st.wMinute.ToString());
}