C++中的时间函数

来源:互联网 发布:数据分析能力 编辑:程序博客网 时间:2024/06/07 01:14
1.用于获取当前系统时间Format 可按格式输出
CTime time = CTime::GetCurrentTime();

string str = time.Format("%Y-%m-%d %H:%M:%S");


2. 用于秒级别的运算,一般用于函数观察程序运行时间,优化

#Include <windows.h>

double t 1= clock();

    double t2 = clock();

cout<<t2-t1<<endl

 3.time_t 函数,获取系统当前时间

#include <time.h>

time_t t = time(0);
char tmp[64]; 
    strftime( tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S",localtime(&t) );


0 0