没有系统性总结很多种方法,这里笔者以为最简单的获取系统时间(时分秒)的方法
#include <iostream>
#include <ctime>
using namespace std;
int main(){
time_t now;
time(&now);
struct tm * p;
p = localtime(&now);
cout << p->tm_hour << " " << p->tm_min << " " << p->tm_sec << endl;//结果直接就是当前时间的时分秒
system("time");//用来与上方的时间进行比(这个也可以获得系统时间,只不过没法将时分秒单独分离出来)(而且这个可以用来改系统时间)
system("pause");
return 0;
}
运行结果: