GetLocalTime获取系统时间信息。函数原型:
VOID WINAPI GetLocalTime(
__out LPSYSTEMTIME lpSystemTime
);
先来看SYSTEMTIME结构:
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
可知该函数可以很方便的得到当前时间的有关信息。
1 举一个小例子: 2 #include <Windows.h> 3 void main() 4 { 5 SYSTEMTIME sysTime; 6 GetLocalTime(&sysTime); 7 char szYear[5] = {0}; 8 char szMonth[3] = {0}; 9 char szDate[3] = {0}; 10 char szDayOfWeek[3] = {0}; 11 char szHour[3] = {0}; 12 char szMinute[3] = {0}; 13 char szSecond[3] = {0}; 14 char szFullTime[50] = {0}; 15 sprintf_s(szFullTime, "%s年:%s月:%s日:星期%s:%s时:%s分:%s秒", szYear, szMonth, szDate, szDayOfWeek, szHour, szMinute, szSecond); //szFullTime:2015年:10月:18日:星期0:0时:48分:49秒 16 17 18 }