#include <iostream>
#include<string>
using namespace std;
#include <ctime>
int main()
{
time_t curtime;
time(&curtime);
cout << "1970到目前经过秒数:" << time(&curtime) << endl;
cout << "本地日期和时间:" << ctime(&curtime) << endl;
tm* nowtime = localtime(&curtime);
// 输出tm结构的年月日
cout << "年: " << 1900 + nowtime->tm_year << endl;
string a =to_string( 1900 + nowtime->tm_year);
cout << "月: " << 1 + nowtime->tm_mon << endl;
string b = to_string(1 + nowtime->tm_mon);
cout << "日: " << nowtime->tm_mday << endl;
string c = to_string(nowtime->tm_mday);
cout << "时间: " << nowtime->tm_hour << ":";
string d = to_string(nowtime->tm_hour);
cout << nowtime->tm_min << ":";
cout << nowtime->tm_sec << endl;
string e = a +"-" + b + "-" + c + "-" + d;
cout << "=======" << endl;
cout << e << endl;
return 0;
}
C++获取当前时间
最新推荐文章于 2023-11-20 22:32:33 发布