cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the Unix timestamp from STM F7?

Tim Russell
Associate III

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?

2 REPLIES 2

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

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()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..