2018-10-19 06:24 AM
I need to get the Unix timestamp from my F7 application.
I know how to use the HAL_RTC_GetTime() function that returns the time in the RTC_TimeTypeDef, but I want the raw epoch time since 1/1/1970.
Is there a function to get this timestamp?
2018-10-19 06:52 AM
See <time.h> as defined in C99, see perhaps also https://en.wikipedia.org/wiki/C_date_and_time_functions . Create a struct tm variable, fill it in with the broken-down time/date values, and use mktime() to convert it to time_t type. While time_t according to standard is implementation-defined, the usual implementation is using UNIX epoch.
JW
2018-10-19 07:20 AM
In embedded you need to create the routines for facilitate time on your platform.
http://www.keil.com/support/man/docs/armlib/armlib_chr1359122848467.htm
http://www.keil.com/support/man/docs/armlib/armlib_chr1359122848748.htm
You'd also need to code routines to get the date/time to/from the RTC and into the epoch of your choice.
I tend to manage UNIX time via SysTick()