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
getlocaltime (kernel32)
 
.
Summary
Retrieves the current local date and time.

C# Signature:

[DllImport("kernel32.dll")]
static extern void GetLocalTime(out SYSTEMTIME lpSystemTime);

VB Signature:

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

User-Defined Types:

None.

Notes:

If you want to get the current system date and time expressed in Coordinated Universal Time (UTC) format, use GetSystemTime instead.

Also:

See SYSTEMTIME.

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

   Public Sub test1()
     Dim currenttime As SYSTEMTIME
     GetLocalTime(currenttime)

     Console.WriteLine("day: {0}", currenttime.Day)
     Console.WriteLine("dayofweek: {0}", currenttime.DayOfWeek)
     Console.WriteLine("month: {0}", currenttime.Month)
     Console.WriteLine("year: {0}", currenttime.Year)
     Console.WriteLine("hour: {0}", currenttime.Hour)
     Console.WriteLine("minute: {0}", currenttime.Minute)
     Console.WriteLine("second: {0}", currenttime.Second)
     Console.WriteLine("milliseconds: {0}", currenttime.Milliseconds)
   End Sub
End Class

Alternative Managed API:

Do you know one? Please contribute it!

System.DateTime.Now

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