mBed RTC get time hours, mins and seconds

Hello everyone,

I need to get the current hour, min and sec using RTC. I am using stm32f767ZI. I used the example code for RTC and I am able to see the current time.
Can anyone tell me how to get the hours, min and sec separately.

time_t seconds = time(NULL);
printf(“Time as a basic string = %s\n”, ctime(&seconds));
strftime(buffer, 32, “%H:%M:%S %p\n”, localtime(&seconds));
printf(“Time as a custom formatted string = %s”, buffer);

This code prints out the time but I am not clear how to get the hours, mins and sec as integers separately. Thanks.


1 Like

Thanks. I did according to the example and It worked. This is the code i used.
struct tm *current_time;
current_time = localtime(&seconds);
printf(“Current hour: %d\n”, current_time->tm_hour);