The SYSTEMTIME structure represents a date and time using individual members for the month, day, year, weekday, hour, minute, second, and milliseconds.
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME;
| Member | Type | Description |
|---|---|---|
| wYear | WORD | Year (e.g., 2025). |
| wMonth | WORD | Month of the year (1-12). |
| wDayOfWeek | WORD | Day of the week (0=Sunday, 6=Saturday). Ignored when converting to/from FILETIME. |
| wDay | WORD | Day of the month (1-31). |
| wHour | WORD | Hour in 24‑hour format (0-23). |
| wMinute | WORD | Minute (0-59). |
| wSecond | WORD | Second (0-59). |
| wMilliseconds | WORD | Milliseconds (0-999). |
Convert the current system date and time to a SYSTEMTIME structure and display it.
#include
#include
int main(void) {
SYSTEMTIME st;
GetLocalTime(&st);
printf("Current time: %04d-%02d-%02d %02d:%02d:%02d.%03d\n",
st.wYear, st.wMonth, st.wDay,
st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
return 0;
}