您好!
我正在尝试将 Unix epoch 时间转换为 CCS V10/TI v20.x.y 编译器中 MSP430使用的时间。 大概 TI 编译器使用从1900-01-01 00:00:00开始的 epoch 时间、至少以下代码指示了这种情况。
#include "time.h" // Unix epoch time entered via UART console uint32_t unixEpochTime = (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3]; unixEpochTime += (uint32_t)2208988800; /*CCS use time since 1900-1-1 00:00:00*/ struct tm* calendarTime = gmtime(&unixEpochTime); uint8_t debugInfo[48]; sprintf(debugInfo, "%04d-%02d-%02d %02d:%02d:%02d, ", calendarTime->tm_year + 1900, calendarTime->tm_mon + 1, calendarTime->tm_mday, calendarTime->tm_hour, calendarTime->tm_min, calendarTime->tm_sec); sendCmdArray((uint8_t *)debugInfo, 21); // Output via UART console
如果我输入0x00000001 1秒钟(从 epoch 开始)或00000E10持续1小时(从 epoch 开始)、我将按预期获得以下日历时间:
1970-01-01 00:00:01 // 1 second since epoch, as expected 1970-01-01 01:00:00 // 1 hour since epoch, as expected
但是、如果我在 epoch 之后的1天内输入0x00015180、我会得到一个不同于我预期的输出:
1970-01-01 05:47:44 // It should be 1970-01-02 00:00:00
我在这里错过了什么?
谢谢。