您的位置:首页 > 编程语言 > C语言/C++

c++ 时间处理

2015-08-05 15:26 609 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: