工具/软件: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