#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;
cout<< t->tm_year + 1900<<
t->tm_mon + 1<<
t->tm_mday<<
t->tm_hour<<
t->tm_min<<
t->tm_sec<<endl;
return 0;
}
`结果::
1566378427
2019821977
此方法为了 将Windows下的VS C++程序 迁移到Ubuntu上时,需要调整一部分原始代码!
Ubuntu C++代码获取系统时间
最新推荐文章于 2025-03-08 09:45:19 发布
本文介绍了一个C++程序,用于处理Windows下VSC++程序在迁移到Ubuntu时的时间转换问题。通过调整代码,实现从本地时间到UTC时间的转换,并考虑了时区差异。
5293

被折叠的 条评论
为什么被折叠?



