1 using System;
2 using System.Runtime.InteropServices;
3
4 class SysDateTime
5 {
6 private struct SYSTEMTIME
7 {
8 public ushort wYear;
9 public ushort wMonth;
10 public ushort wDayOfWeek;
11 public ushort wDay;
12 public ushort wHour;
13 public ushort wMinute;
14 public ushort wSecond;
15 public ushort wMilliseconds;
16 }
17
18 [DllImport("Coredll.dll")]
19 private static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);
20
21 public static void SetDateTime(DateTime dt)
22 {
23 #region Codes==========================================================
24
25 SYSTEMTIME sysTime = new SYSTEMTIME();
26
27 sysTime.wYear = Convert.ToUInt16(dt.Year);
28 sysTime.wMonth = Convert.ToUInt16(dt.Month);
29 sysTime.wDay = Convert.ToUInt16(dt.Day);
30 sysTime.wDayOfWeek = Convert.ToUInt16(dt.DayOfWeek);
31 sysTime.wHour = Convert.ToUInt16(dt.Hour);
32 sysTime.wMinute = Convert.ToUInt16(dt.Minute);
33 sysTime.wSecond = Convert.ToUInt16(dt.Second);
34 sysTime.wMilliseconds = Convert.ToUInt16(dt.Millisecond);
35
36 SetLocalTime(ref sysTime);
37
38 #endregion
39 }
40 } // class
41
2 using System.Runtime.InteropServices;
3
4 class SysDateTime
5 {
6 private struct SYSTEMTIME
7 {
8 public ushort wYear;
9 public ushort wMonth;
10 public ushort wDayOfWeek;
11 public ushort wDay;
12 public ushort wHour;
13 public ushort wMinute;
14 public ushort wSecond;
15 public ushort wMilliseconds;
16 }
17
18 [DllImport("Coredll.dll")]
19 private static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);
20
21 public static void SetDateTime(DateTime dt)
22 {
23 #region Codes==========================================================
24
25 SYSTEMTIME sysTime = new SYSTEMTIME();
26
27 sysTime.wYear = Convert.ToUInt16(dt.Year);
28 sysTime.wMonth = Convert.ToUInt16(dt.Month);
29 sysTime.wDay = Convert.ToUInt16(dt.Day);
30 sysTime.wDayOfWeek = Convert.ToUInt16(dt.DayOfWeek);
31 sysTime.wHour = Convert.ToUInt16(dt.Hour);
32 sysTime.wMinute = Convert.ToUInt16(dt.Minute);
33 sysTime.wSecond = Convert.ToUInt16(dt.Second);
34 sysTime.wMilliseconds = Convert.ToUInt16(dt.Millisecond);
35
36 SetLocalTime(ref sysTime);
37
38 #endregion
39 }
40 } // class
41