Skip to content
Michael Miller edited this page Mar 4, 2017 · 4 revisions

Using the time_t and the standard C time API

You have two choices that will both work. Either you can use this library to access the RTC device or you can used a modified version of this library that fully embraces the standard C time API.

Use this library:

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

and to set time just do this ...

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

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

Use a modified version of this library:

Instead of using this library, you can use the modified version of this library from here GitHub/Smz/Arduino-RTCtime. You can find it in the library manager as "RTCtime by smz".

This is very useful when you need to use a library that already uses the standard C time API or write code that needs to be compatible outside the Arduino ecosystem.

Clone this wiki locally