方法一:
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;