Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
setlocaltime (coredll)
 

coredll is for smart devices, not desktop Windows. Therefore, this information only applies to code using the .NET Compact Framework. To see if information for setlocaltime in other DLLs exists, click on Find References to the right.

.
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

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions