[DllImport("coredll.dll", SetLastError=true)]
static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);
Private Shared Function SetLocalTime(ByRef time As SYSTEMTIME) As Boolean
End Function
public struct SYSTEMTIME
{
public short year;
public short month;
public short dayOfWeek;
public short day;
public short hour;
public short minute;
public short second;
public short milliseconds;
}
Private Structure SYSTEMTIME
Public Year As Short
Public Month As Short
Public DayOfWeek As Short
Public Day As Short
Public Hour As Short
Public Minute As Short
Public Second As Short
Public Milliseconds As Short
End Structure
Do you know one? Please contribute it!
This function set the system time with consideration to locale settings and summer time.
To set the date and time without consideration to the locale settings use SetSystemTime.
Please add some!
C# Sample Code
static void SetSystemTime(System.DateTime dt)
{
SYSTEMTIME time2;
time2.year = (short)dt.Year;
time2.month = (short)dt.Month;
time2.day = (short)dt.Day;
time2.hour = (short)dt.Hour;
time2.minute = (short)dt.Minute;
time2.second = (short)dt.Second;
time2.milliseconds = (short)dt.Millisecond;
time2.dayOfWeek = (short)dt.DayOfWeek;
SetLocalTime(ref time2);
}
To see sample code for VB, please go to SetSystemTime.