c++ 时间处理

#include <iostream>
#include <time.h>

void getCalendarTime()
{
	time_t lt;
	lt = time(NULL);
	std::cout<<"The Calendar Time is "<<lt<<std::endl;
	//當下時間 - 1970年1月1日0時0秒
}

void getProcessTime()
{
	clock_t start, finish;
	double duration;
	start = clock();
	/*do process*/
	finish = clock();
	duration = (double)(finish - start);
	std::cout<<"Process Time is "<<start<<" "<<duration<<" "<<finish<<std::endl;
}

void getHours()
{
	struct tm *local;
	time_t t;
	t = time(NULL);
	local = localtime(&t);
	std::cout<<"Local hour is : "<<local->tm_hour<<std::endl;
	local = gmtime(&t);
	std::cout<<"UTC hour is : "<<local->tm_hour<<std::endl;
}

int main ()
{
	getCalendarTime();
	getProcessTime();
	getHours();

	
	return 0;
}

你可能感兴趣的:(C++,时间处理)