GetSystemTime
Retrieves the current system time, in Coordinated Universal Time (UTC) format.
VOID GetSystemTime(
LPSYSTEMTIME lpSystemTime
);
LPSYSTEMTIME lpSystemTime
);
Parameters
| Parameter | Type | Description |
|---|---|---|
lpSystemTime |
LPSYSTEMTIME |
A pointer to a SYSTEMTIME structure that receives the current system date and time.
The wDayOfWeek member is always filled.
|
Return Value
This function does not return a value.
Remarks
The GetSystemTime function retrieves the current system time. The system time is maintained by the hardware clock.
The time is returned in UTC. If you need the local time, use the GetLocalTime function.
The SYSTEMTIME structure can represent dates between January 1, 1601 (New Year's Day, 1 AD in the Gregorian calendar, although the Gregorian calendar was adopted at different times in different places) and December 31, 60055.
The SYSTEMTIME structure is defined as follows:
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *LPSYSTEMTIME;
wYear: Year.wMonth: Month (1 = January, ..., 12 = December).wDayOfWeek: Day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday).wDay: Day of the month.wHour: Hour (0-23).wMinute: Minute (0-59).wSecond: Second (0-59).wMilliseconds: Millisecond (0-999).
Requirements
| Component | Value |
|---|---|
| Minimum supported client | Windows 2000 Professional [desktop apps only] |
| Minimum supported server | Windows 2000 Server [desktop apps only] |
| Target Platform | Windows |
| Header | sysinfoapi.h (include windows.h) |
| Library | Use Kernel32.lib |
| DLL | Kernel32.dll |
See Also
Example
#include <windows.h>
#include <stdio.h>
int main() {
SYSTEMTIME st;
GetSystemTime(&st);
printf("Current system time (UTC):\n");
printf(" Year: %d\n", st.wYear);
printf(" Month: %d\n", st.wMonth);
printf(" Day: %d\n", st.wDay);
printf(" Day of week: %d\n", st.wDayOfWeek);
printf(" Hour: %d\n", st.wHour);
printf(" Minute: %d\n", st.wMinute);
printf(" Second: %d\n", st.wSecond);
printf(" Milliseconds: %d\n", st.wMilliseconds);
return 0;
}