1 使用time_t time( time_t * timer ) 精确到秒
2 使用clock_t clock() 得到的是CPU时间 精确到1/CLOCKS_PER_SEC秒
3 计算时间差使用double difftime( time_t timer1,time_t timer0 )
4 使用DWORD GetTickCount() 精确到毫秒
5 如果使用MFC的CTime类,可以用CTime::GetCurrentTime()
程序主要通过当前系统日历的struct tm结构体获得,主要代码如下,#include <stdio.h>#include <time.h> //程序功能输出当前时间在24H下的小时数 int main(int argc, char *argv[]){ struct tm *ptr; time_t lt; time(<);//当前系统时间 ptr=localtime(<);//获取本地日历时间指针 printf("hour=%d(24H )\n",ptr->tm_hour);//输出24H下的小时数 return 0;}结构体tm定义如下,struct tm {int tm_sec; /* 秒–取值区间为[0,59] */int tm_min; /* 分 - 取值区间为[0,59] */int tm_hour; /* 时 - 取值区间为[0,23] */int tm_mday; /* 一个月中的日期 - 取值区间为[1,31] */int tm_mon; /* 月份(从一月开始,0代表一月) - 取值区间为[0,11] */int tm_year; /* 年份,其值从1900开始 */int tm_wday; /* 星期–取值区间为[0,6],其中0代表星期天,1代表星期一,以此类推 */int tm_yday; /* 从每年的1月1日开始的天数–取值区间为[0,365],其中0代表1月1日,1代表1月2日,以此类推 */int tm_isdst; /* 夏令时标识符,实行夏令时的时候,tm_isdst为正。不实行夏令时的进候,tm_isdst为0;不了解情况时,tm_isdst()为负。*/long int tm_gmtoff; /*指定了日期变更线东面时区中UTC东部时区正秒数或UTC西部时区的负秒数*/const char *tm_zone; /*当前时区的名字(与环境变量TZ有关)*/};





