user80257: I am getting

error: 'getLocalTime' was not declared in this scope

when I am compiling this code for ESP8266, however works for ESP32:
#include "time.h"

void gettime()
{
  static int16_t delaycount = 0 ;                         // To reduce number of NTP requests
  static int16_t retrycount = 100 ;

  if ( timeinfo.tm_year )                                 // Legal time found?
  {
    sprintf ( timetxt, "%02d:%02d:%02d",                  // Yes, format to a string
              timeinfo.tm_hour,
              timeinfo.tm_min,
              timeinfo.tm_sec ) ;
  }
  if ( --delaycount <= 0 )                                // Sync every few hours
  {
    delaycount = 7200 ;                                   // Reset counter
    if ( timeinfo.tm_year )                               // Legal time found?
    {
      dbgprint ( "Sync TOD, old value is %s", timetxt ) ;
    }
    dbgprint ( "Sync TOD" ) ;
    if ( !getLocalTime ( &timeinfo ) )                    // Read from NTP server
    {
      dbgprint ( "Failed to obtain time!" ) ;             // Error
      timeinfo.tm_year = 0 ;                              // Set current time to illegal
      if ( retrycount )                                   // Give up syncing?
      {
        retrycount-- ;                                    // No try again
        delaycount = 5 ;                                  // Retry after 5 seconds
      }
    }
    else
    {
      sprintf ( timetxt, "%02d:%02d:%02d",                // Format new time to a string
                timeinfo.tm_hour,
                timeinfo.tm_min,
                timeinfo.tm_sec ) ;
      dbgprint ( "Sync TOD, new value is %s", timetxt ) ;
    }
  }
}

What shall I replace getLocalTime with?

user37622: It looks like the esp8266 Arduino core don't have a similar function.
The getLocalTime in esp32 arduino core is a simple function implemented in esp32-hal-time.c.
bool getLocalTime(struct tm * info, uint32_t ms)
{
    uint32_t start = millis();
    time_t now;
    while((millis()-start) <= ms) {
        time(&now);
        localtime_r(&now, info);
        if(info->tm_year > (2016 - 1900)){
            return true;
        }
        delay(10);
    }
    return false;
}

The function compiles on esp8266 arduino as it is so you can copy it to your sketch.

80257: <p>I am getting</p>
<blockquote>
<p>error: 'getLocalTime' was not declared in this scope</p>
</blockquote>
<p>when I am compiling this code for ESP8266, however works for ESP32:</p>
<pre><code>#include &quot;time.h&quot;

void gettime()
{
  static int16_t delaycount = 0 ;                         // To reduce number of NTP requests
  static int16_t retrycount = 100 ;

  if ( timeinfo.tm_year )                                 // Legal time found?
  {
    sprintf ( timetxt, &quot;%02d:%02d:%02d&quot;,                  // Yes, format to a string
              timeinfo.tm_hour,
              timeinfo.tm_min,
              timeinfo.tm_sec ) ;
  }
  if ( --delaycount &lt;= 0 )                                // Sync every few hours
  {
    delaycount = 7200 ;                                   // Reset counter
    if ( timeinfo.tm_year )                               // Legal time found?
    {
      dbgprint ( &quot;Sync TOD, old value is %s&quot;, timetxt ) ;
    }
    dbgprint ( &quot;Sync TOD&quot; ) ;
    if ( !getLocalTime ( &amp;timeinfo ) )                    // Read from NTP server
    {
      dbgprint ( &quot;Failed to obtain time!&quot; ) ;             // Error
      timeinfo.tm_year = 0 ;                              // Set current time to illegal
      if ( retrycount )                                   // Give up syncing?
      {
        retrycount-- ;                                    // No try again
        delaycount = 5 ;                                  // Retry after 5 seconds
      }
    }
    else
    {
      sprintf ( timetxt, &quot;%02d:%02d:%02d&quot;,                // Format new time to a string
                timeinfo.tm_hour,
                timeinfo.tm_min,
                timeinfo.tm_sec ) ;
      dbgprint ( &quot;Sync TOD, new value is %s&quot;, timetxt ) ;
    }
  }
}
</code></pre>
<p>What shall I replace getLocalTime with?</p>
 37622: <p>It looks like the esp8266 Arduino core don't have a similar function.</p>
<p>The getLocalTime in esp32 arduino core is a simple function implemented in esp32-hal-time.c.</p>
<pre><code>bool getLocalTime(struct tm * info, uint32_t ms)
{
    uint32_t start = millis();
    time_t now;
    while((millis()-start) &lt;= ms) {
        time(&amp;now);
        localtime_r(&amp;now, info);
        if(info-&gt;tm_year &gt; (2016 - 1900)){
            return true;
        }
        delay(10);
    }
    return false;
}
</code></pre>
<p>The function compiles on esp8266 arduino as it is so you can copy it to your sketch.</p>
