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.

[参考译文] TM4C1294NCPDT:从 time.h 头文件设置代码内部的时区

Guru**** 2476675 points


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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/687021/tm4c1294ncpdt-setting-timezone-inside-the-code-from-the-time-h-header-file

器件型号:TM4C1294NCPDT

尊敬的 TI 成员:

我尝试将从远程 NTP 服务器获取的 UTC 时间转换为我使用了以下函数代码的本地时间:

void setTime (uint32_t t)
{
time_t ts;
struct tm;
struct tm td;

seconds_set (t);

时间(&T);
TM =*本地时间(&ts);

System_printf ("NTP 服务器时间:%s\n"、asctime (&TM));

system_flush();
} 

这里、我再次得到 UTC 时间、而 localtime 函数无法按照函数名称的建议将 UTC 时间转换为本地时间。

我尝试找到其根本原因、因此我发现 time.h 头文件中有一个时区结构、但它只有其数据结构、并且没有可在该数据结构上运行的函数。

以下是时区数据结构 time.h 文件中的代码片段:

/************* //*
时区结构定义 */
********* /
typedef 结构
{
日间;
超长时区;/*秒(UTC 以西)。 奇怪但传统的*/
字符 tzname[4];
char dstname[4];
}TZ;

extern _data_access TZ _tz; 

因此,我想知道如何使用这个时区数据结构,以及如何使 localtime 函数返回我所在区域的本地时间。

此致

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

    是否未显示"timeZone"值(可能)已被清除?   如果 向 UTC/GMT 添加零秒-'UTC'(IS)'Expected!'(预计!)

    注释指示应将"时区"加载为"从 GMT 向西移动时、时间差(转换为秒[小时* 3600]-时区与 GMT 之间的时间差"。   

    注意:我们尚未使用该函数-此响应基于(希望)您所呈现数据的逻辑使用...