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(<m, 0, sizeof(struct tm));
if( sscanf(args, "%d-%d-%d %d:%d:%d", <m.tm_year, <m.tm_mon, <m.tm_mday, <m.tm_hour, <m.tm_min, <m.tm_sec) == 6 )
{
ltm.tm_year -= 1900; // 1900 is correct? or 1970?
ltm.tm_mon -= 1;
ltm.tm_isdst = -1;
time_t newTime = mktime(<m);
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...."