1 #include<ctime> 2 #include<iostream> 3 using namespace std; 4 5 int main(){ 6 time_t timer; 7 8 timer=time(NULL);//或者 time(&timer); 9 10 cout<<timer<<endl;//the number of seconds since 00:00 hours, Jan 1, 1970 11 struct tm *ptr; 12 ptr=localtime(&timer); 13 cout<<asctime(ptr)<<endl;//asctime can Convert tm structure to string 14 }
原文:https://www.cnblogs.com/NoerForest/p/14467785.html