好贷网好贷款

STL中的时间

发布时间:2016-12-4 1:50:24 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"STL中的时间",主要涉及到STL中的时间方面的内容,对于STL中的时间感兴趣的同学可以参考一下。

#include <iostream> #include <ctime> using namespace std; #ifndef CLOCKS_PER_SEC #define CLOCKS_PER_SEC 1000 #endif int main() { char tempbuf[128]; struct tm * mytime; time_t myclock; clock_t start ,finish; time_t tstart ,tfinish ,tcurr; double duration; long count = 600000000L; time(&myclock); mytime = localtime(&myclock); cout << "Usage of asctime(): " << endl; //ssctime() 用于将指定的时间以字符串的形式输出。 cout << "asctime() : Current Data and Time :" << asctime(mytime) << endl; cout << "Usage of ctime(): " << endl; cout << "ctime(): Current Data and Time :" << ctime(&myclock) << endl; cout << "Usage of clock(): " << endl; start = clock(); while(count--); finish = clock(); duration = (double)(finish - start)/CLOCKS_PER_SEC; cout << "clock(): Consume " << duration << " second." << endl << endl; cout << "Usage of difftime() :" << endl; count = 600000000L; time(&tstart); while(count--); time(&tfinish); duration = tfinish - tstart; cout << "time(): Consume " << duration << "seconds." << endl << endl; cout << "Usage of gmtime() (GMT):" << endl; time(&tcurr); mytime = gmtime(&tcurr); cout << "The current time : " << mytime->tm_year + 1900 << " ," << mytime->tm_mon + 1 << " ," << mytime->tm_mday << " ,"; cout << mytime->tm_hour << " :" << mytime->tm_min << " :" << mytime->tm_sec << " , "; cout << (mytime->tm_isdst? "Night.":"Daylight") << ", " << mytime->tm_wday << ", " << mytime->tm_yday << "th." << endl; cout << endl; cout << "Usage of localtime() :" << endl; time(&tcurr); mytime = localtime(&tcurr) ; cout << "The current time : " << mytime->tm_year + 1900 << " ," << mytime->tm_mon + 1 << " ," << mytime->tm_mday << " ,"; cout << mytime->tm_hour << " :" << mytime->tm_min << " :" << mytime->tm_sec << " , "; cout << (mytime->tm_isdst? "Night.":"Daylight") << ", " << mytime->tm_wday << ", " << mytime->tm_yday << "th." << endl; cout << endl; cout << "Usage of mktime() :" << endl; tcurr = mktime(mytime); cout << "The seconds from 1970/1/1 0:0:0" << tcurr << "seconds." << endl << endl; cout << "Usage of time() :" << endl; time(&tcurr); cout << "time transformed by localtime() :" << asctime(localtime(&tcurr)) ; cout << "time transformed by gmtime() :" << asctime(gmtime(&tcurr)) << endl; cout << endl; cout << "Usage of strftime() :" << endl; mytime = localtime(&tcurr); strftime(tempbuf ,128 ,"Today is %A ,dat %d of %B in the year %Y.\n" ,mytime); cout << tempbuf << endl; return 0; }

上一篇:关于GPIO的故事
下一篇:RootKit hook之[二] SSDT hook

相关文章

关键词: STL中的时间

相关评论