TRC
Dependents: RTC_terminal HorlogeSimple
Diff: RTC_IUT.cpp
- Revision:
- 1:b85409cf9f7b
- Parent:
- 0:f17b3622fae1
--- a/RTC_IUT.cpp Fri May 29 16:45:33 2020 +0000 +++ b/RTC_IUT.cpp Sat May 30 16:09:00 2020 +0000 @@ -156,39 +156,21 @@ bool Rtc::SetTimeString(char * timestring) { bool success = false; - char * p; time_t seconds = time(NULL); struct tm *t = localtime(&seconds); - - p = strtok(timestring," /"); - if (p != NULL) { - t->tm_mday = atoi(p) ; - p = strtok(NULL, " /"); - if (p != NULL) { - t->tm_mon = atoi(p)-1; - p = strtok(NULL, " /"); - if (p != NULL) { - t->tm_year = atoi(p) - 1900; - p = strtok(NULL, " :"); - if (p != NULL) { - t->tm_hour = atoi(p); - p = strtok(NULL, " :"); - if (p != NULL) { - t->tm_min = atoi(p); - p = strtok(NULL, " (:"); - if (p != NULL) { - t->tm_sec = atoi(p); - success = true; // if we get to here, we're good - seconds = mktime(t); - //seconds = seconds ; - //printf("ss%u \n",seconds); - set_time(seconds); - - } - } - } - } - } + unsigned int dd,MM,yyyy,hh,mm,ss; + //printf("str : %s\r\n",timestring); + success=sscanf(timestring,"%d/%d/%d %d:%d:%d",&dd,&MM,&yyyy,&hh,&mm,&ss); + if(success) { + //printf("dd=%d\r\n",dd); + t->tm_mday = dd ; + t->tm_mon = MM-1; + t->tm_year = yyyy - 1900; + t->tm_hour = hh; + t->tm_min = mm; + t->tm_sec = ss; } + seconds = mktime(t); + set_time(seconds); return success; }