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.

[参考译文] CCS/CC1352P:CCS mktime()仍会返回

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

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/895286/ccs-cc1352p-ccs-mktime-still-returns

器件型号:CC1352P

工具/软件:Code Composer Studio

您好!

mktime()不返回 UTC 时间。 根据对此类问题的搜索,实施了下一个代码来解决该问题:

1. #include

2. project->Properties->Build->Arm Compiler->Predefined Symbols->_TI_TIME_USes_64=1。 该定义将 time_t 从32位转换为64位、格式为32位、结果也不正确。

3.在调用 mktime()之前,时区设置为0

tz.timezone =0;
_tz.日光= 0; 

对于我的时区、它仍然返回 UTC +时区+ 1小时夏令时:UTC+10800 + 3600。

如何使用 mktime()命令在没有夏时制和没有时区的情况下获得 UTC 时间?

TM tm_current{};
time_t CurrentTime{};
tm_current.tm_sec = rtc->getSeconds ();
tm_current.tm_min = rtc->getMinutes ();
tm_current.tm_hour = rtc->getHours ();
tm_current.tm_wday = 0;
tm_current.tm_mday = rtc->getDate ();
tm_current.tm_mon = rtc->getMonth ()-1;//因为 RTC 月份为1到12。 TM 结构的范围为0-11
TM_CURRENT.TM_Year= RTC->getYear ()+100;//因为 RTC 的年份为2000。 TM strc 的范围为1900
TM_Current.TM_yday = 0;
TM_Current.TM_isdst = 0;

_tz.timezone = 0;//_tz 在 time.h
_tz.day = 0;
CurrentTime = mktime (&TM_current); 

ARM 编译器版本:版本: 18.12.4.LTS

Code Composer Studio 版本: 9.3.0.00012

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

    我使用这个简单的程序执行了一个测试...

    #include 
    
    void main()
    {
    struct tm tm_current;
    time_t CurrentTime;
    
    tm_curration.tm_sec = 0;
    TM_CURRENT_MIN = 0;
    TM_CURRENT_Hour = 1;
    tm_curration.tm_mday = 1;
    tm_curry.tm_mon = 0;
    tm_curry.tm_year = 1970 - 1900;
    TM_CURRENT_ISDst = 0;
    
    tz.timezone = 0;//_tz 在 time.h 中的某个位置定义
    tz.日光= 0;
    
    CurrentTime = mktime (&TM_current);
    } 

    我使用 定义的预处理器符号_TI_TIME_USS_64进行编译。  因此、epoch 为1970年1月1日、time_t 为64位有符号类型。  如果我按如图所示运行它、则 mktime 返回3600。  如果我评论这些任务...

    tz.timezone = 0;//_tz 在 time.h 中的某个位置定义
    tz.日光= 0; 

    mktime 返回25200。  这些是我所期望的结果。

    话虽如此、我确信我忽略了一些东西。  请使用类似的示例来演示您的问题、该示例对输入到 mktime 的结构中的字段使用特定值。

    谢谢、此致、

    乔治

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

    你好 ,乔治,谢谢。   mktime 返回与您的示例相同的值。  找到问题。