GetCurrentTime(),GetLocalTime(),GetSystemTime()之间的区别
2014-11-07 19:32
387 查看
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);
输出结果: 2001年5月8日星期一19:35:40 PM
下附一些时间函数:
The following functions are used with system time.
The following functions are used with local time.
The following functions are used with file time.
The following functions are used with MS-DOS date and time.
The following functions are used with Windows time.
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. |
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. |
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. |
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. |
Function | Description |
---|---|
GetTickCount | Retrieves the number of milliseconds that have elapsed since the system was started. |
相关文章推荐
- GetCurrentTime(),GetLocalTime(),GetSystemTime()之间的区别
- GetCurrentTime(),GetLocalTime(),GetSystemTime()之间的区别
- GetCurrentTime(),GetLocalTime(),GetSystemTime()之间的区别
- GetCurrentTime(),GetLocalTime(),GetSystemTime()之间的区别
- VC中GetCurrentTime(), GetSystemTime( ), GetLocalTime( )的区别
- GetSystemTime和GetLocalTime的区别
- GetSystemTime,GetLocalTime,GetCurrentTime异同分析
- GetSystemTime,GetLocalTime,GetCurrentTime
- GetSystemTime,GetLocalTime,GetCurrentTime
- Windows API一日一练(70)GetSystemTime和GetLocalTime函数
- GetSystemTime和GetLocalTime
- [MFC]两个GetCurrentTime()的区别
- Windows API一日一练(70)GetSystemTime和GetLocalTime函数
- java的System.currentTimeMillis()和System.nanoTime()有什么区别?
- windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTim
- windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTime
- GetLocalTime() 和 GetSystemTime()
- 使用GetLocalTime()和GetSystemTime()所获得的时间不同
- GetSystemTime和GetLocalTime
- GetLocalTime和GetSystemTime