This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] 编译器:gmtime()-错误转换

Guru**** 2530710 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/570129/compiler-gmtime---wrong-conversion

工具/软件:TI C/C++编译器

您好,

我希望我在正确的论坛上提出问题。

我的问题是标准的"time.h"库,特别是gmtime()函数。

基本上,我从互联网检索NTP时间戳,并想使用gmtime()将其转换为时间结构。 转换成功,但我得到的时间总是GMT  + 6小时。 我的问题是,为什么要换6个小时? 我错过了什么吗?

我的代码是:

时间_t cur_time;
struct TM *tm_time;

CUR_TIME = GetNTPTime();//从因特网获取NTP时间(我自己的函数)
tm_time = gmtime(&cur_time); //将NTP时间转换为时间结构

UART_PRINT ("%s",Asctime (TM_time));//将时间打印为字符串

我得到的是: 2017年1月星期二23:06:04,但正确的GMT时间实际上是: 2017年1月星期二17:06:04

我使用的是15.12 384.3LTS编译器。

如果有任何建议,我将不胜感激。

谢谢你

丹尼尔