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
Download Visual Studio Add-In

SetLocalTime (kernel32)
 
.
Summary
Sets the current local time and date.

C# Signature:

[DllImport("kernel32.dll")]
static extern bool SetLocalTime([In] ref SYSTEMTIME lpLocalTime);

VB Signature:

<DllImport("kernel32.dll")> _
Shared Function SetLocalTime(ByRef time As SYSTEMTIME) As Boolean
End Function

User-Defined Types:

None.

Notes:

Please add some!

Tips & Tricks:

Please add some!

Sample Code in VB:

Imports System.Runtime.InteropServices

Public Class Class1
   <StructLayout(LayoutKind.Sequential)> _
   Private Structure SYSTEMTIME
     <MarshalAs(UnmanagedType.U2)> Public Year As Short
     <MarshalAs(UnmanagedType.U2)> Public Month As Short
     <MarshalAs(UnmanagedType.U2)> Public DayOfWeek As Short
     <MarshalAs(UnmanagedType.U2)> Public Day As Short
     <MarshalAs(UnmanagedType.U2)> Public Hour As Short
     <MarshalAs(UnmanagedType.U2)> Public Minute As Short
     <MarshalAs(UnmanagedType.U2)> Public Second As Short
     <MarshalAs(UnmanagedType.U2)> Public Milliseconds As Short
   End Structure

   <DllImport("kernel32.dll")> _
   Private Shared Sub GetLocalTime(ByRef time As SYSTEMTIME)
   End Sub

   <DllImport("kernel32.dll")> _
   Private Shared Function SetLocalTime(ByRef time As SYSTEMTIME) As Boolean
   End Function

   Public Sub SetsLocalTimeHourToEight()
     Dim currentTime As SYSTEMTIME
     GetLocalTime(currentTime)

     currentTime.Hour = 8

     SetLocalTime(currentTime)
   End Sub
End Class

Alternative Managed API:

Do you know one? Please contribute it!

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
Find References
Show Printable Version
Revisions