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.

Compiler/CC3220SF-LAUNCHXL: Wrong mktime conversion

Part Number: CC3220SF-LAUNCHXL
Other Parts Discussed in Thread: CC3220SF

Tool/software: TI C/C++ Compiler

I set the internal RTC of CC3220SF to 1st January 2000, then I try to readback its value:

time_t GetEpoch(void)
{
    _i16 ret;
    _u8 pConfigOpt = SL_DEVICE_GENERAL_DATE_TIME;
    _u16 pConfigLen = sizeof(SlDateTime_t);

    SlDateTime_t dateTime = {0};
    ret = sl_DeviceGet(SL_DEVICE_GENERAL, &pConfigOpt, &pConfigLen, (unsigned char *) &dateTime);
    ASSERT_ON_ERROR(ret);

    struct tm t;
    time_t t_of_day;

    t.tm_year = dateTime.tm_year - 1900;
    t.tm_mon = dateTime.tm_mon - 1;
    t.tm_mday = dateTime.tm_day;
    t.tm_hour = dateTime.tm_hour;
    t.tm_min = dateTime.tm_min;
    t.tm_sec = dateTime.tm_sec;
    t.tm_isdst = -1;
    t_of_day = mktime(&t);

    UART_PRINT("SlDateTime_t: %d/%d/%d %d:%d:%d\r\n", dateTime.tm_year, dateTime.tm_mon, dateTime.tm_day, dateTime.tm_hour, dateTime.tm_min, dateTime.tm_sec);
    UART_PRINT("struct tm: %d/%d/%d %d:%d:%d\r\n", t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
    UART_PRINT("time_t   : %lld\r\n", t_of_day);

    return t_of_day;
}


Here the output:

SlDateTime_t: 2000/1/1 0:0:0                                              
struct tm: 100/0/1 0:0:0                                                  
time_t   : 2305849197122252192

Please note I'm using 64-bit time functions.

Both SlDateTime and tm structs are correct - why the time_t value is wrong? Is there any mistake in my code?

  • Hi Mark,

    I'm not very familiar with the mktime function itself, but I don't see anything obviously wrong in the code above. I found another thread describing a discrepancy between mktime and another function umktime--which uses a different ephoch time. I've attached the thread below for you to check out. Perhaps you can try this umktime function instead?

    If you still run into issues I'd recommend posting to the CCS forum for additional support on these specific functions.

  • Since 1st Jan 1900 to the 1st Jan 1970 there are 2,208,988,800 seconds.
    The Unix time (since 1st Jan 1970) for 1st Jan 2000 is 946684800.

    Hence the result should be: 3,155,673,600.
    Instead mktime returns 2,305,849,197,122,252,192 that is a HUGE number.