GetCurrentTime(),GetLocalTime(),GetSystemTime()之间的区别

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值