GetLocalTime
时间: 2023-08-13 20:04:37 浏览: 51
GetLocalTime是一个Windows API函数,用于获取当前系统的本地时间。它可以获取年、月、日、时、分、秒和毫秒等时间信息。
使用GetLocalTime函数需要包含Windows.h头文件,并调用以下函数原型:
```c
VOID GetLocalTime(
LPSYSTEMTIME lpSystemTime
);
```
参数lpSystemTime是一个指向SYSTEMTIME结构体的指针,用于接收获取到的本地时间信息。SYSTEMTIME结构体定义如下:
```c
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME;
```
调用GetLocalTime函数后,系统会将当前的本地时间信息填充到lpSystemTime指向的结构体中。
以下是一个简单的示例代码:
```c
#include <windows.h>
#include <stdio.h>
int main() {
SYSTEMTIME st;
GetLocalTime(&st);
printf("Current local time: %02d-%02d-%04d %02d:%02d:%02d.%03d",
st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
return 0;
}
```
上述代码将获取到的当前本地时间信息打印输出。
总而言之,GetLocalTime是一个Windows API函数,用于获取当前系统的本地时间信息。