C++程序执行时间计算

关于 time.h

https://www.runoob.com/cprogramming/c-standard-library-time-h.html

#include <iostream>
#include <ctime>

using namespace std;

int main()
{
    struct tm t;    //tm结构指针
    char stTmp[32];
    time_t now;        //声明time_t类型变量
    now = time(NULL);//获取系统日期和时间   time(&now); 
    localtime_s(&t, &now);    //获取当地日期和时间
    cout<<t.tm_year + 1900<<"";
    cout<<t.tm_mon + 1<<"";
    cout<<t.tm_mday<<"";
    cout<<""<<t.tm_wday<<"  ";//为了输出好看。。
    cout<<t.tm_hour<<"";
    cout<<t.tm_min<<"";
    cout<<t.tm_sec<<"";
    return 0;
}

//与time_t 相比,还有一个clock_t,是在记录cpu时间上使用的,两者要分清。

原文地址:https://www.cnblogs.com/yoriko/p/12237180.html