Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 10 months ago.
Time Problem ---> gmtime() Function
i try to use the function "gmtime()" from the Time lib. But i think it dosent work with the mbed Platform.
have enyone any Idea how can i convert the "Time_t" value to the Hour/minut/second !?
Thanks
1 Answer
5 years, 10 months ago.
Something I use, not very special but works for me. You need to declare the variables somewhere in your code (e.g. RTCsecond etc.). Converts to string and integer values.
RTC snip
void readRTC() { time_t seconds = time(NULL); strftime(timebuf,50,"%H:%M:%S", localtime(&seconds)); strftime(datebuf,50,"%a %d %b %Y", localtime(&seconds)); char buf[80]; strftime(buf, 2,"%S", localtime(&seconds)); RTCsecond = atoi(buf); strftime(buf, 2,"%M", localtime(&seconds)); RTCminute = atoi(buf); strftime(buf, 2,"%H", localtime(&seconds)); RTChour = atoi(buf); strftime(buf, 2,"%d", localtime(&seconds)); RTCdayofmonth = atoi(buf); strftime(buf, 2,"%w", localtime(&seconds)); RTCdayofweek = atoi(buf); strftime(buf, 2,"%m", localtime(&seconds)); RTCmonth = atoi(buf); strftime(buf, 2,"%y", localtime(&seconds)); RTCyear = atoi(buf); }