編碼的世界 / 優質文選 / 生物

C++ linux獲取系統時間


2021年7月16日
-   

頭文件
  • time.h

代碼
#include <iostream>
#include <time.h>
using namespace std;
int main() {
time_t tt;
time( &tt );
tt = tt + 8*3600; // transform the time zone
tm* t= gmtime( &tt );
cout << tt << endl;
printf("%d-%02d-%02d %02d:%02d:%02d
",
t->tm_year + 1900,
t->tm_mon + 1,
t->tm_mday,
t->tm_hour,
t->tm_min,
t->tm_sec);
return 0;
}

結果

熱門文章