setlocaltime (coredll)
Last changed: -112.94.10.70

.
Summary
Sets the date and time on the system.

C# Signature:

[DllImport("coredll.dll", SetLastError=true)]
   static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);

VB Signature:

   Private Shared Function SetLocalTime(ByRef time As SYSTEMTIME) As Boolean
   End Function

User-Defined Types C#:

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;
}

User-Defined Types VB:

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

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

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.

Tips & Tricks:

Please add some!

Sample Code:

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.

Documentation