Updating a RTC with NTP time

I'm using an Adafruit HUZZAH feather board (ESP32). It has Wi-Fi built in and I'm successfully pulling the time from an NTP server (pool.ntp.org).

I'd like to update a RTC (Real Time Clock) on an add-on board with the NTP time I obtain, but for some reason I can't structure the line correctly to update the RTC time.

Here is what I'm trying to do:

rtc.adjust(&timeinfo, %Y, %B, %d, %H, %M, %S);

This gives an error which states:

expected primary-expression before '%' token

This is what works to update the RTC that I tried to modify:

rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));  // This sets the time to 1/21/2014 at 3:00 am.

For reference, here is the entire function I'm using:

void printLocalTime()
{
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
      //Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
      Serial.println("Failed to obtain time");
    return;
  }
  Serial.print("NTP time: ");
  Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
  rtc.adjust(&timeinfo, %Y, %B, %d, %H, %M, %S);     // Update the RTC if it found the time from the internet.
  Serial.println("Updated the RTC on the Adalogger board.");
}

How do I correctly modify it to use the &timeinfo statement?

I'd like to update a RTC (Real Time Clock) on an add-on board with the NTP time I obtain, but for some reason I can't structure the line correctly to update the RTC time.

rtc.adjust() is a function within RTClib.h. Is that the library you are using with your external RTC?

There is a DateTime object as part of that library as well.

rtc.adjust() can take several forms of the DateTime object.

As you state, this is one of the formulations that you have used

rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));  // This sets the time to 1/21/2014 at 3:00 am.

rtc.adjust() can also accept a DateTime object with a unix timestamp as the parameter.

For example

rtc.adjust(DateTime(1596411254));//unixTimeStamp

Will set the time to be 2020/8/2 23:34:14

You will need to adjust the NTP time stamp to seconds from 1970 and to local time.