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