Linux下可以通过:
struct tm * gmtime (const time_t * timer); //获得gmt(UTC)时间
struct tm * localtime (const time_t * timer); //获得本地时间
- #include
- #include
- #include
- using namespace std;
-
- string getTimeStr(struct tm* t)
- {
- char tStr[50] = {0};
- snprintf(tStr, sizeof(tStr), "%04d-%02d-%02d %02d:%02d:%02d", (1900 + t->tm_year), ( 1 + t->tm_mon), t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
- return string(tStr);
- }
-
- int main(){
- time_t ts = time(nullptr);
- struct tm* tUTC = gmtime(&ts);
- cout<<"UTC time:"<<getTimeStr(tUTC)<
- struct tm* tLocal = localtime(&ts);
- cout<<"Local time:"<<getTimeStr(tLocal)<
- return 0;
- }
运行程序输出:
UTC time:2022-08-21 03:54:53
Local time:2022-08-21 11:54:53
-
相关阅读:
数据中台的五个关键要素
亚马逊美国站灯具UL认证灯串UL588认证办理
vue使用window.location.href 跳转失败
微信小程序异常处理(持续记录中)
Android 11.0 无源码apk授予QUERY_ALL_PACKAGES权限
22年最新金九银十面试必备
protobuf在linux下载编译和使用
电脑办公助手之桌面便签,助力高效率办公
SAT DPLL CDCL
每日一题——自动补全——1972
-
原文地址:https://blog.csdn.net/jiemashizhen/article/details/126449271