1.
GetCurrentTime()
GetCurrentTime()只和16位版本的windows兼容,在32位windows下最好用gettickcount();
2. GetLocalTime()
GetLocalTime()在不同的机器中会有不同的结果,这和你在控制面板中的时区设置有关. 该函数是获取的系统当前所属时区的时间, 比如说, 在北京时区, 那么获取的该时间的时间.
3. GetSystemTime()
GetSystemTime()获取的格林尼治时间, 是 全球标准时间 .
SYSTEMTIME stUTC;
GetSystemTime(&stUTC);
TCHAR chBuf[nBufSize];
wsprintf(chBuf,_T("UTC: %u/%u/%u %u:%u:%u:%u %d\r\n"),
stUTC.wYear, stUTC.wMonth, stUTC.wDay,
stUTC.wHour, stUTC.wMinute, stUTC.wSecond,
stUTC.wMilliseconds,stUTC.wDayOfWeek);
4. GetTickCount()
GetTickCount() 获取的是从设备开机后的毫秒数. 不包括系统的挂起时间 .
主要的应用:
dwOldTime = GetTickCount();
DoSomeThing();
dwTimeElapsed = GetTickCount() - dwOldTime;
获取某段程序执行所需的时间.
5. 更好的办法:“now函数”
例如:formatdatetime('yyyy ''年'' m ''月'' d ''日''dddd '+'hh:mm:ssAM/PM',now);
GetCurrentTime()只和16位版本的windows兼容,在32位windows下最好用gettickcount();
2. GetLocalTime()
GetLocalTime()在不同的机器中会有不同的结果,这和你在控制面板中的时区设置有关. 该函数是获取的系统当前所属时区的时间, 比如说, 在北京时区, 那么获取的该时间的时间.
3. GetSystemTime()
GetSystemTime()获取的格林尼治时间, 是 全球标准时间 .
SYSTEMTIME stUTC;
GetSystemTime(&stUTC);
TCHAR chBuf[nBufSize];
wsprintf(chBuf,_T("UTC: %u/%u/%u %u:%u:%u:%u %d\r\n"),
stUTC.wYear, stUTC.wMonth, stUTC.wDay,
stUTC.wHour, stUTC.wMinute, stUTC.wSecond,
stUTC.wMilliseconds,stUTC.wDayOfWeek);
4. GetTickCount()
GetTickCount() 获取的是从设备开机后的毫秒数. 不包括系统的挂起时间 .
主要的应用:
dwOldTime = GetTickCount();
DoSomeThing();
dwTimeElapsed = GetTickCount() - dwOldTime;
获取某段程序执行所需的时间.
5. 更好的办法:“now函数”
例如:formatdatetime('yyyy ''年'' m ''月'' d ''日''dddd '+'hh:mm:ssAM/PM',now);
输出结果: 2001年5月8日星期一19:35:40 PM
下附一些时间函数:
The following functions are used with system time.
Function | Description |
---|---|
GetSystemTime | Retrieves the current system date and time in UTC format. |
GetSystemTimeAdjustment | Determines whether the system is applying periodic time adjustments to its time-of-day clock. |
LocalFileTimeToFileTime | Converts a local file time to a file time based on UTC. |
SetSystemTime | Sets the current system time and date. |
SetSystemTimeAdjustment | Enables or disables periodic time adjustments to the system's time-of-day clock. |
SystemTimeToFileTime | Converts a system time to a file time. |
SystemTimeToTzSpecificLocalTime | Converts a UTC time to a specified time zone's corresponding local time. |
TzSpecificLocalTimeToSystemTime | Converts a local time to a UTC time. |
The following functions are used with local time.
Function | Description |
---|---|
FileTimeToLocalFileTime | Converts a UTC file time to a local file time. |
GetLocalTime | Retrieves the current local date and time. |
GetTimeZoneInformation | Retrieves the current time-zone parameters. |
SetLocalTime | Sets the current local time and date. |
SetTimeZoneInformation | Sets the current time-zone parameters. |
SystemTimeToTzSpecificLocalTime | Converts a UTC time to a specified time zone's corresponding local time. |
TzSpecificLocalTimeToSystemTime | Converts a local time to a UTC time. |
The following functions are used with file time.
Function | Description |
---|---|
CompareFileTime | Compares two file times. |
FileTimeToLocalFileTime | Converts a UTC file time to a local file time. |
FileTimeToSystemTime | Converts a file time to system time format. |
GetFileTime | Retrieves the date and time that a file was created, last accessed, and last modified. |
GetSystemTimeAsFileTime | Retrieves the current system date and time in UTC format. |
LocalFileTimeToFileTime | Converts a local file time to a file time based on UTC. |
SetFileTime | Sets the date and time that a file was created, last accessed, or last modified. |
SystemTimeToFileTime | Converts a system time to a file time. |
The following functions are used with MS-DOS date and time.
Function | Description |
---|---|
DosDateTimeToFileTime | Converts MS-DOS date and time values to a file time. |
FileTimeToDosDateTime | Converts a file time to MS-DOS date and time values. |
The following functions are used with Windows time.
Function | Description |
---|---|
GetTickCount | Retrieves the number of milliseconds that have elapsed since the system was started. |