//time.t下的函数.#include <iostream>#include <time.h>#include <windows.h>#include <vector>using namespace std;#pragma warning(disable:4996)//重要函数./*1.time_t time(0); //返回的是从1970.1.1凌晨0点到当前时间的秒数.2.tm* localtime(time_t*); //把秒数转化为具体的时间.tm是一个结构体.具体成员可以右键,然后转到定义~3.double difftime(time_t t1, time_t t2); //比较两个time_t对象的差异.也就是相差的秒数.4.char* ctime(const time_t*); //把time_t对象转化为一段字符串.5.time_t mktime(struct tm* ); //把一个具体时间转化为一个秒数.6.clock_t clock(); //相当于一个时钟,两个clock_t对象的差值,代表间隔的时间,单位是毫秒,更精确了.*/ int main() { //第一个例子: time_t s = time(0); //time(0)返回的是从1970.1.1凌晨0点到当前时间的秒数,它是一个一直在变化的值. cout << s << endl; //第二个例子: /*tm *temp = localtime(&s); int hour = temp->tm_hour; //几点. int minute = temp->tm_min; //几分. int month = temp->tm_mon; //几月 int week = temp->tm_wday; //周几.0代表周日. int year = temp->tm_year + 1900; //几年. int second = temp->tm_sec; //几秒. int day = temp->tm_mday; //几天. cout << year << "/" << month << "/" << day << "/" << hour << ":" << minute << ":" << second << " " << "星期" << week << endl; cout << __DATE__ << " " << __TIME__ << endl; //当然关于时间,也可以用C语言的宏来体现.同样非常的快.*/ //第三个例子: /*time_t s = time(0); //间隔3000毫秒. Sleep(3000); time_t temp = time(0); cout << difftime(temp, s) << endl;*/ //第四个例子: /*time_t s = time(0); //把秒数转换为字符串. char *q = ctime(&s); cout << q << endl;*/ //第五个例子: /*clock_t temp = clock(); vector<int> w; for (int i = 0; i < 1000000; ++i) { w.push_back(i); } clock_t s = clock(); //两个时钟之差为间隔的时间.单位是毫秒!!! cout << s - temp << endl;*/ system("pause"); return 0; }