time.h 全部使用举例

#include <time.h>
#include <stdio.h> 
using namespace std;

int main()
{
   clock_t start_t, end_t;
   double total_t;
   int i;
 
   start_t = clock();
   printf("程序启动,start_t = %ld\n", start_t);
    
   printf("开始一个大循环,start_t = %ld\n", start_t);
   for(i=0; i< 10000000; i++)
   {
   }
   end_t = clock();
   printf("大循环结束,end_t = %ld\n", end_t);
   
   total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
   printf("CPU 占用的总时间:%f\n", total_t  );
   printf("程序退出...\n"); 

	time_t rawtime; 
	time_t rawtime2; 
	struct tm *info;
	struct tm *info2;
	char buffer[80];
	
	time(&rawtime);
	printf("当前的本地时间和日期:%s", ctime(&rawtime));
	
	info=localtime(&rawtime);
	printf("当前的本地时间和日期:%s", asctime(info));
	
	info2 = gmtime(&rawtime );
	printf("标准的本地时间和日期:%s", asctime(info2));
	
	rawtime2=mktime ( localtime(&rawtime) );
	printf("当前的本地时间和日期:%s", ctime(&rawtime2));
  
 	strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", info);
   	printf("格式化的日期 & 时间 : |%s|\n", buffer );
	
	return 0;
}

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页