Skip to main content
Tim Russell
Associate II
October 19, 2018
Question

How to get the Unix timestamp from STM F7?

  • October 19, 2018
  • 2 replies
  • 3187 views

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?

    This topic has been closed for replies.

    2 replies

    waclawek.jan
    Super User
    October 19, 2018

    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

    Tesla DeLorean
    Guru
    October 19, 2018

    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 VenmoUp vote any posts that you find helpful, it shows what's working..