#include <string>
#include <iostream>
#include <time.h>
#include <fstream>
using namespace std;
//本函数用于获取当前系统的时间,使用前请传入获取时间的string的引用
void getSystemTime(string & stime){
time_t t = time( 0 );
char tmp[64];
strftime( tmp, sizeof(tmp), "%Y/%m/%d %X ",localtime(&t) );
stime=tmp;
}
int main(){
string nowtime;//存储获取的系统的时间
//输出起始时间
getSystemTime(nowtime);
cout<<nowtime<<endl;
//这一步仅仅是为了耗费程序的时间
ofstream fout("tt.txt");
for(long i=0; i<1000*1000; ++i){fout<<i<<endl;}
//输出结束时间
getSystemTime(nowtime);
cout<<nowtime<<endl;
system("pause");
return 0;
}
程序运行结果截图:
