Windows API Reference

Win32 API Reference

Kernel32 Functions: Time Functions

This section provides documentation for time-related functions available in the Kernel32.dll library, which are fundamental for managing and retrieving system time and date information on Windows.

GetSystemTime

Retrieves the current system date and time in Coordinated Universal Time (UTC).

VOID GetSystemTime(
  LPSYSTEMTIME lpSystemTime
);

GetLocalTime

Retrieves the current local date and time.

VOID GetLocalTime(
  LPSYSTEMTIME lpSystemTime
);

SetLocalTime

Sets the current local date and time. This function requires administrator privileges.

BOOL SetLocalTime(
  CONST SYSTEMTIME *lpSystemTime
);

GetSystemTimeAsFileTime

Retrieves the current system date and time in UTC as a FILETIME structure.

VOID GetSystemTimeAsFileTime(
  LPFILETIME lpSystemTimeAsFileTime
);

GetTickCount

Retrieves the number of milliseconds that have elapsed since the system was started.

DWORD GetTickCount(
  VOID
);

GetTickCount64

Retrieves the number of milliseconds that have elapsed since the system was started. This function returns a 64-bit value.

ULONGLONG GetTickCount64(
  VOID
);

FileTimeToSystemTime

Converts a file time (a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC)) to a system date and time structure.

BOOL FileTimeToSystemTime(
  CONST FILETIME *lpFileTime,
  LPSYSTEMTIME lpSystemTime
);

SystemTimeToFileTime

Converts a system date and time structure to a file time.

BOOL SystemTimeToFileTime(
  CONST SYSTEMTIME *lpSystemTime,
  LPFILETIME lpFileTime
);

TimeToJulianDate

Converts a date and time to a Julian date.

double TimeToJulianDate(
  CONST SYSTEMTIME *lpSystemTime
);

GetSystemTime

Synopsis:

VOID GetSystemTime(
  LPSYSTEMTIME lpSystemTime
);

Parameters:

  • lpSystemTime: A pointer to a SYSTEMTIME structure that receives the current system date and time.

Description: This function retrieves the current system date and time in UTC. The SYSTEMTIME structure contains members for year, month, day, day of the week, hour, minute, second, and milliseconds.

GetLocalTime

Synopsis:

VOID GetLocalTime(
  LPSYSTEMTIME lpSystemTime
);

Parameters:

  • lpSystemTime: A pointer to a SYSTEMTIME structure that receives the current local date and time.

Description: This function retrieves the current local date and time, taking into account the system's time zone and daylight saving time settings.

SetLocalTime

Synopsis:

BOOL SetLocalTime(
  CONST SYSTEMTIME *lpSystemTime
);

Parameters:

  • lpSystemTime: A pointer to a SYSTEMTIME structure containing the desired local date and time.

Description: This function sets the current local date and time. It requires administrator privileges to execute successfully. If the call is successful, it returns TRUE; otherwise, it returns FALSE.

GetSystemTimeAsFileTime

Synopsis:

VOID GetSystemTimeAsFileTime(
  LPFILETIME lpSystemTimeAsFileTime
);

Parameters:

  • lpSystemTimeAsFileTime: A pointer to a FILETIME structure that receives the current system date and time in UTC.

Description: This function retrieves the current system date and time in UTC as a FILETIME structure, which is a 64-bit value. This format is often used for comparisons and calculations.

GetTickCount

Synopsis:

DWORD GetTickCount(
  VOID
);

Description: This function returns the number of milliseconds that have elapsed since the system was started. The return value wraps around approximately every 49.7 days.

GetTickCount64

Synopsis:

ULONGLONG GetTickCount64(
  VOID
);

Description: This function is similar to GetTickCount but returns a 64-bit value, providing a much longer interval before wrapping around. This makes it more suitable for applications that need to measure durations exceeding 49.7 days.

FileTimeToSystemTime

Synopsis:

BOOL FileTimeToSystemTime(
  CONST FILETIME *lpFileTime,
  LPSYSTEMTIME lpSystemTime
);

Parameters:

  • lpFileTime: A pointer to a FILETIME structure to be converted.
  • lpSystemTime: A pointer to a SYSTEMTIME structure that receives the converted date and time.

Description: Converts a FILETIME structure, representing a specific point in time in UTC, into a more human-readable SYSTEMTIME structure. Returns TRUE on success, FALSE on failure.

SystemTimeToFileTime

Synopsis:

BOOL SystemTimeToFileTime(
  CONST SYSTEMTIME *lpSystemTime,
  LPFILETIME lpFileTime
);

Parameters:

  • lpSystemTime: A pointer to a SYSTEMTIME structure containing the date and time to convert.
  • lpFileTime: A pointer to a FILETIME structure that receives the converted file time.

Description: Converts a SYSTEMTIME structure into a FILETIME structure. This is useful for storing or comparing date and time values in a standardized format. Returns TRUE on success, FALSE on failure.

TimeToJulianDate

Synopsis:

double TimeToJulianDate(
  CONST SYSTEMTIME *lpSystemTime
);

Parameters:

  • lpSystemTime: A pointer to a SYSTEMTIME structure containing the date and time to convert.

Description: Converts a SYSTEMTIME structure into a Julian date, a continuous count of days since a specific historical epoch. This is often used in astronomical or chronological calculations.