C++获取当前时间(使用C库)

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <ctime>
 
int main()
{
    
    
	
	time_t t = time(nullptr);
	struct tm* now = localtime(&t);
 
	std::stringstream timeStr;
    
    // 以下依次把年月日的数据加入到字符串中
	timeStr << now->tm_year + 1900 << "年";
	timeStr << now->tm_mon + 1 << "月";
	timeStr << now->tm_mday << "日 ";
	timeStr << now->tm_hour << ":";
	timeStr << now->tm_min << ":";
	timeStr << now->tm_sec;
 
	std::cout << timeStr.str();
 
	getchar();
	return 0;
}

参考:https://blog.csdn.net/weixin_39445116/article/details/122473569

猜你喜欢

转载自blog.csdn.net/gls_nuaa/article/details/131499574
今日推荐