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.

CC1310 set Timezone and date management



Hi all,

I would manage the datetime on CC1310, but seems that I can not handle the timezone. Also mktime function returns a value different from other compilers! Why? Default timezone is CST.

//From system to human dateTime
String getTime(void)
{
    struct tm *ltm;
    time_t now;
    char risp[40];

    now = time(NULL);
    ltm = gmtime(&now);

    strftime(risp, 40, "%Y-%m-%d %H:%M:%S", ltm);

    return risp;
}

//From human to system dateTime
void setTime(String args)
{
    struct tm ltm;
    memset(&ltm, 0, sizeof(struct tm));

    if( sscanf(args, "%d-%d-%d %d:%d:%d", &ltm.tm_year, &ltm.tm_mon, &ltm.tm_mday, &ltm.tm_hour, &ltm.tm_min, &ltm.tm_sec) == 6 )
    {
        ltm.tm_year  -=  1900; // 1900 is correct? or 1970?
        ltm.tm_mon   -=  1;
        ltm.tm_isdst  =  -1;

        time_t newTime = mktime(&ltm);

        Seconds_set(newTime -2208988800); //ATTENTION, I HAVE TO SUBTRACT "2208988800"!!
    } 
}

For example: if I set "2016-11-25 16:05:22" and the i use getTime() it returns to me "2016-11-25 22:05:22"; mktime returns "3689078722" instead of "148...."