c++ vs中如何操作时间
代码如下:
#include#include using namespace std; int main() { cout << "Hello World!" << endl; const time_t now = time(NULL); cout << "时间戳:" << now << endl; struct tm systime; localtime_s(&systime, &now); // 输出 tm 结构的各个组成部分 cout << "年: " << 1900 + systime.tm_year << endl; cout << "月: " << 1 + systime.tm_mon << endl; cout << "日: " << systime.tm_mday << endl; cout << "时间: " << systime.tm_hour << ":" << systime.tm_min << ":" << systime.tm_sec << endl; }
结果:
Hello World! 时间戳:1649294557 年: 2022 月: 4 日: 7 时间: 9:22:37