您的位置:首页 > 其它

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.

FunctionDescription
GetSystemTimeRetrieves the current system date and time in UTC format.
GetSystemTimeAdjustmentDetermines whether the system is applying periodic time adjustments to its time-of-day clock.
LocalFileTimeToFileTimeConverts a local file time to a file time based on UTC.
SetSystemTimeSets the current system time and date.
SetSystemTimeAdjustmentEnables or disables periodic time adjustments to the system's time-of-day clock.
SystemTimeToFileTimeConverts a system time to a file time.
SystemTimeToTzSpecificLocalTimeConverts a UTC time to a specified time zone's corresponding local time.
TzSpecificLocalTimeToSystemTimeConverts a local time to a UTC time.
The following functions are used with local time.

FunctionDescription
FileTimeToLocalFileTimeConverts a UTC file time to a local file time.
GetLocalTimeRetrieves the current local date and time.
GetTimeZoneInformationRetrieves the current time-zone parameters.
SetLocalTimeSets the current local time and date.
SetTimeZoneInformationSets the current time-zone parameters.
SystemTimeToTzSpecificLocalTimeConverts a UTC time to a specified time zone's corresponding local time.
TzSpecificLocalTimeToSystemTimeConverts a local time to a UTC time.
The following functions are used with file time.

FunctionDescription
CompareFileTimeCompares two file times.
FileTimeToLocalFileTimeConverts a UTC file time to a local file time.
FileTimeToSystemTimeConverts a file time to system time format.
GetFileTimeRetrieves the date and time that a file was created, last accessed, and last modified.
GetSystemTimeAsFileTimeRetrieves the current system date and time in UTC format.
LocalFileTimeToFileTimeConverts a local file time to a file time based on UTC.
SetFileTimeSets the date and time that a file was created, last accessed, or last modified.
SystemTimeToFileTimeConverts a system time to a file time.
The following functions are used with MS-DOS date and time.

FunctionDescription
DosDateTimeToFileTimeConverts MS-DOS date and time values to a file time.
FileTimeToDosDateTimeConverts a file time to MS-DOS date and time values.
The following functions are used with Windows time.

FunctionDescription
GetTickCountRetrieves the number of milliseconds that have elapsed since the system was started.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: