方法一:
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#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;