using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace SystemTime_CS
{
    public partial class Form1 : Form
    {
        [DllImport("coredll.dll")]
        private extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);

        [DllImport("coredll.dll")]
        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());
        }


        public Form1()
        {
            InitializeComponent();
            #if DEBUG
                MinimizeBox = false;
            #else
                MinimizeBox = true;
            #endif
        }

        private void butGetTime_Click(object sender, EventArgs e)
        {
            GetTime();
        }

        private void butSetTime_Click(object sender, EventArgs e)
        {
            SetTime();
        }

    }
}