Automatic time retrieval?

Hi I use an ESP8622 NodeMCU from AZdelivery. I just discovered, that this module does retrieve date and time from somewhere without that I call an NTPudp server or log in into wifi at all!!
This minimalistic code produces the attached output over serial. In the first loop iteration it reports 1.1.1970 and a second later it has the actual time out of nowhere!! Only that it is off by one hour becouse it doesn't care about my time zone. How can it pull that off? As you see there is no line of code from me that sets the time or only initializes wifi.
I discovered it, because when I do set the time deliberately with correct time zone (+1), erratically the time gets reset to GMT.
To use it as it is given it would be perfect if I could set the time zone to some system variable. Does anyone know how I would have to do this?
Update:
setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1);
does the trick apparently.

char chBuffer[128];
void setup() {
  Serial.begin(9600);
  while (!Serial) {}
}


void loop() {
  time_t tn = time(nullptr);
  struct tm * tmPointer = localtime(&tn);
  strftime (chBuffer, sizeof(chBuffer), "%a, %d %b %Y %H:%M:%S",  tmPointer);
  Serial.println(chBuffer);
  delay(1000);
}

2020-11-18 20_32_20-HTerm 0.8.5.png

2020-11-18 20_32_20-HTerm 0.8.5.png

If you found the answer, please edit the thread title to add, "SOLVED".

I havent found the answer yet to how the chip is it doing to sync the time all by itself.

The native time library functions run by default. Does your board have an RTC?

Also, the ESP8266 will remember the last valid wlan credentials it has been given, even if a new sketch has been uploaded.
If you’ve used the board before in your wlan, that could explain things.

I'd expect that this board does not have an RTC, at least there is no battery to power one. The behaviour at boot up, that it first starts with 1.1.1970 is a sign that there is no RTC.
It might be that it uses previously known wlan credentials. But anyway it is very odd that it provides a synchronizing function that is mentioned nowhere. Everyone is programming NTPudp calls to get the time and I now threw it all out of my code and get that synching for free from some internal mechanism. Probably this is valid for all ESP8622 boards and a lot of people bother to program something that is already provided. Than this should be made "public".

This example is from the ESP8266 Arduino git hub:

There is no explicit UDP transaction initiated to retrieve a time from an NTP server.

I’m also curious about how much just works and how much is cached.

I'm interested in where all the callbacks are (yeah I know, I should go hunting). I have such a sketch running on an ESP32 and it syncs like that. But, I would like to gain some control over the time update - read and possibly modify the update interval and choose a more efficient (closer) NTP server. Probably some other things I haven't thought of yet... I did delve into some documentation and found some statements suggesting a 30 minute default update interval, but how can I be sure? One reason I want to do this, I prefer to not remain wifi connected all the time, for my clocks I try to save power by only going on line to fetch the time, then disconnect. I do that every few hours. I wonder (again here I'm guessing which I don't want to do...) if it automatically performs an update any time there is a connection? Anyway, it's hard to deal with such an opaque process.

the example says following

// OPTIONAL: change SNTP startup delay
// a weak function is already defined and returns 0 (RFC violation)
// it can be redefined:
//uint32_t sntp_startup_delay_MS_rfc_not_less_than_60000 ()
//{
// //info_sntp_startup_delay_MS_rfc_not_less_than_60000_has_been_called = true;
// return 60000; // 60s (or lwIP's original default: (random() % 5000))
//}

and:
// OPTIONAL: change SNTP update delay
// a weak function is already defined and returns 1 hour

noiasca:
the example says following

// OPTIONAL: change SNTP startup delay
// a weak function is already defined and returns 0 (RFC violation)
// it can be redefined:
//uint32_t sntp_startup_delay_MS_rfc_not_less_than_60000 ()
//{
// //info_sntp_startup_delay_MS_rfc_not_less_than_60000_has_been_called = true;
// return 60000; // 60s (or lwIP's original default: (random() % 5000))
//}

and:
// OPTIONAL: change SNTP update delay
// a weak function is already defined and returns 1 hour

So what does that mean? How do you change startup delay and update interval?

EDIT:
Never mind, think I figured it out. You just implement those functions and return the value you want. The time system will call them automatically to get the parameter.