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.

[参考译文] RM46L852:如何将 Unix 时间转换为从 SNTP 服务器获取的 UTC 时间

Guru**** 2394305 points


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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/664374/rm46l852-how-to-convert-the-unix-time-to-utc-time-fetched-from-sntp-server

器件型号:RM46L852

您好!

我在我的软件中使用的是 Lwip 堆栈 、在我的项目中使用了集成的 SNTP 和.h 文件。

我已经调试了软件、发现每当控制到达下一行的断点时

静态空
SNTP 过程(u32_t *接收_时间戳)

/*将 SNTP 时间(基于1900)转换为 UNIX GMT 时间(基于1970)
*@TODO:如果 MSB 为1、则 SNTP 时间基于2036!
*
time_t =(ntohl (receive_timestamp[0])- DIFF_SEC_1900_1970);

我们在"t"实例中得到秒值。 例如 t = 1518585734

我的问题是、如何将 UNIX 时间转换为 UTC 时间(YY:MM:DATE:HR:min:SEC)。 是否有现成的功能可用?

我是否应使用以下代码?

静态空
SNTP 过程(u32_t *接收_时间戳)


/*将 SNTP 时间(基于1900)转换为 UNIX GMT 时间(基于1970)
*@TODO:如果 MSB 为1、则 SNTP 时间基于2036!
*
time_t timenow =(ntohl (receive_timestamp[0])- diff_SEC_1900_1970);

//格式化时间,"ddd yyyy-mm-dd hh:mm:ss zzz"

struct tm ts;

char buf[80];

TS =*本地时间(&timenow);

strfttime (buf、sizeof (buf)、"%a %Y-%m-%d %H:%M:%S %Z"、&ts);

请提供建议。

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

    我们的 LWIP 演示不支持此功能。 您可以包含 SNTP、但我们没有计划帮助移植和调试这些代码。