Linux下C语言编程——几种可以获取系统时间的函数


#include 
#include 

int main()
{

	time_t rawtime;
	struct tm * timeinfo;
	time(&rawtime);
	timeinfo = localtime(&rawtime);

	printf("\007 the current data/time is %s\n",asctime(timeinfo));

    return 0;
}


#include 
#include 
#include 
#include 
#include 

int main(int argc, char *argv[])
{
	struct timeval tv;
	char mytime[20] = "";
			
	gettimeofday(&tv,NULL);
	strftime(mytime,sizeof(mytime),"%Y%m%d%H%M",localtime(&tv.tv_sec));
					
	printf("Time:%s\n",mytime);
						
	 return 0;
							
}

#include 
#include 
#include 

int main()
{
	char str[30];
	time_t timer;  
	struct tm *tblock;  
    
	timer=time(NULL);  
    tblock=localtime(&timer);
	strcpy(str,asctime(tblock));  
	printf("Local time is: %s",str);  
     
	return 0;
}
第三种和第一种是一样的

你可能感兴趣的:(Linux下C语言基础编程)