3.1 Predefined Macros for Time Initialization

When using the RTC to generate a timestamp, there is a necessity for a correct initial time. Instead of manually entering the initial value of the time struct, it is possible to use predefined GCC macros for application compilation date and time. It may be noted that a fresh compilation must be completed immediately before flashing the device. If there is a delay between compilation and flashing, the initial time will be incorrect, and therefore also the generated timestamp.

As can be seen at gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html, there are strings defined as follows, which can be processed accordingly into the predefined time struct members:
  • __DATE__ string, of the format "Feb 12 1996" for date, month, and year
  • __TIME__ string, of the format "23:59:01" for hour, minute, and second