C++获取系统时间


#include 
#include 
#include 
using namespace std;

string GetCurtime() {
	auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
	转为字符串
	std::stringstream ss;
	ss << std::put_time(std::localtime(&t), "%Y-%m-%d %H:%M:%S");
	std::string str_time = ss.str();
	return str_time;
	
}
#include 
#include 
using namespace std;

string GetCurtime() {

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

}

相关