C++输出当前时间

 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 }

 

posted @ 2021-03-02 10:49  NoerForest  阅读(349)  评论(0)    收藏  举报