To get the system time using Win32 API in C#, you can use the GetSystemTime
function from the kernel32.dll
library. Here's an example:
main.cs821 chars30 lines
Explanation:
System
and System.Runtime.InteropServices
.Program
class with a Main
method.Main
method, it declares an instance of the SYSTEMTIME
struct and invokes the GetSystemTime
API function with a reference to that struct as a parameter.DateTime
struct using the components of the SYSTEMTIME
struct, and specifies that it represents a UTC time.DateTime
value to the console.Note: The GetSystemTime
function returns the system time in UTC. You may need to adjust the time zone depending on your requirements.
gistlibby LogSnag