返回列表 發帖

[作業] time(NULL) 函式 (二)

利用time(NULL)函式, 告訴使用者自格林威治時間1970年1月1日0時0分0秒到現在,
約經過了幾年幾天幾小時幾分鐘幾秒.

附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     long t=time(NULL);
  7.     cout<<"從格林威治時間1970年1月1號0時0分0秒到現在, 經過了"<<t<<"秒!"<<endl;
  8.     cout<<"(約是"<<t/(365*24*60*60)<<"年, ";
  9.     t=t%(365*24*60*60);
  10.     cout<<t/(24*60*60)<<"天, ";
  11.     t=t%(24*60*60);
  12.     cout<<t/(60*60)<<"時, ";
  13.     t=t%(60*60);
  14.     cout<<t/60<<"分, ";
  15.     t=t%60;
  16.     cout<<t<<"秒)"<<endl;
  17.     system("pause");
  18.     return 0;   
  19. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     long t=time(NULL);
  7.     cout<<"time(NULL)為從格林威治時間1970年1月1號0點0分0秒到現在經過了"<<t<<"秒"<<endl;
  8.     cout<<"(約為"<<t/(365*24*60*60)<<"年";
  9.     t=t%(365*24*60*60);
  10.     cout<<t/(24*60*60)<<"天";
  11.     t=t%(24*60*60);
  12.     cout<<t/(60*60)<<"小時";
  13.     t=t%(60*60);
  14.     cout<<t/(60)<<"分";
  15.     t=t%(60);
  16.     cout<<t<<"秒";
  17.     system("pause");         
  18.     return 0;
  19. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     long t=time(NULL);
  7.     cout<<"從格林威治時間1970年1月1號0點0分0秒到現在, 經過了"<<t<<"秒!"<<endl;
  8.     cout<<"(約為"<<t/(365*24*60*60)<<"年";
  9.     t=t%(365*24*60*60);
  10.     cout<<t/(24*60*60)<<"天";
  11.     t=t%(24*60*60);
  12.     cout<<t/(60*60)<<"小時";
  13.     t=t%(60*60);
  14.     cout<<t/(60)<<"分";
  15.     t=t%(60);
  16.     cout<<t<<"秒!)"<<endl;
  17.     system("pause");         
  18.     return 0;
  19. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     long t=time(NULL);
  7.     cout<<"從格林威治時間1970年1月1號0點0分0秒到現在,經過了"<<t<<"秒!"<<endl;
  8.     cout<<"(約為"<<t/(365*24*60*60)<<"年";
  9.     t=t%(365*24*60*60);
  10.     cout<<t/(24*60*60)<<"天";
  11.     t=t%(24*60*60);
  12.     cout<<t/(60*60)<<"小時";
  13.     t=t%(60*60);
  14.     cout<<t/60<<"分";
  15.     t=t%60;
  16.     cout<<t<<"秒)"<<endl;                           
  17.     system("pause");
  18.     return 0;
  19. }
複製代碼

TOP

本帖最後由 張彥承 於 2014-3-22 16:49 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    long t=time(NULL);
  7.    cout<<"從格林威治時間 1970年1月1號 0點0分0秒開始到現在經過"<<t<<"秒"<<endl;
  8.    cout<<"(約為"<<t/(365*24*60*60)<<"年"<<
  9.    t%=(365*24*60*60);
  10.    cout<<t/(24*60*60)<<"月";
  11.    t%=(24*60*60);
  12.    cout<<t/(60*60)<<"天";
  13.    t%=(60*60);
  14.    cout<<t/(60)<<"分";
  15.     t%=(60);
  16.     cout<<t<<"秒)"; endl;
  17. system("pause");   
  18. return 0;   
  19. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     long t=time(NULL);
  7.     cout<<"從格林威治時間1970年1月1號0點0分0秒到現在,經過了"<<t<<"秒!"<<endl;
  8.     cout<<"(約為"<<t/(365*24*60*60)<<"年";
  9.     t=t%(365*24*60*60);
  10.     cout<<t/(24*60*60)<<"天";
  11.     t=t%(24*60*60);
  12.     cout<<t/(60*60)<<"小時";
  13.     t=t%(60*60);
  14.     cout<<t/60<<"分";
  15.     t=t%60;
  16.     cout<<t<<"秒)"<<endl;                           
  17.     system("pause");
  18.     return 0;
  19. }
複製代碼

TOP

返回列表