您的位置:首页 > 其它

25、记录时间的几种方法

2011-09-04 17:23 169 查看
方法一:

View Code

#include <time.h>
#include <stdio.h>
void main( void )
{
time_t ltime;
time( <ime );
printf( "The time is %s\n", ctime(<ime ) );
}


方法二:

struct timeval start;
struct timeval end;
float time_use = 0;
gettimeofday(&start,NULL);
//do some operation
gettimeofday(&end,NULL);
time_use = end.tv_sec - start.tv_sec; //in sec


方法三:

struct tm *local;
time_t t;
time(&t);
local=localtime(&t);
char ctime[30];
memset(ctime, 0, 30);
sprintf(time, "[%d:%d:%d]",local->tm_hour, local->tm_min, local->tm_sec);
cout << time;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: