C++获取系统时间

#include <sstream>
#include <iomanip>
#include <chrono>
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 <string>
#include <time.h>
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;

}

  

posted @ 2022-03-29 22:58  存在与虚无  阅读(101)  评论(0编辑  收藏  举报