Skip to content
Michael Miller edited this page Jan 16, 2023 · 4 revisions

Using the time_t and the standard C time API

RtcDateTime is based on RTC Modules time limitations. It works with seconds that starts at 1/1/2000.
time_t is based on Epoch (aka Unix) time. It works with seconds that start at 1/1/1970.

It is simple to use the time_t type to retrieve and set the time. Just include time.h and replace the RtcDateTime object you normally use with time_t and the method calls to modify it.

To get time just do this ...

time_t now = Rtc.GetDateTime().Epoch32Time();

and to set time just do this ...

time_t now; // initialize it how ever you want
RtcDateTime rtcNow;
rtcNow.InitWithEpoch32Time(now);
Rtc.SetDateTime(rtcNow);

Now you can use the rest of the standard C time API with the time_t variable.

Clone this wiki locally