How can I get the local time automatically, including automatic summer/winter offsets?

hello,
having started WiFi

#include <WiFi.h> // edited, c+p error, it's a  >>>>ESP32 <<<<
 WiFi.begin(ssid, password);

I can config + get the internet time

#include "time.h"
const char* ntpServer = "pool.ntp.org";
const long  gmtOffset_sec = 0;
const int   daylightOffset_sec = 3600;
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
time_t current = time(nullptr);
Serial.print(ctime(&current));

but how can I get the local time automatically, including automatic summer/winter offsets?

maybe here: GitHub - JChristensen/Timezone: Arduino library to facilitate time zone conversions and automatic daylight saving (summer) time adjustments. or here Arduino/NTP-TZ-DST.ino at master · esp8266/Arduino · GitHub

thank you, as far as I can see one has to config a tcr (which is Berlin?) and then it might work.
But how can the program also get the tcr automatically, from the standpoint of my WiFi connection (retrieve and evaluate internet IP)? Similar to how a Raspberry Pi or a Windows PC automatically shows the correct local time incl. summer/winter time-shift?

edited, c+p error, it's a ESP32

That is correct. These have to be manually configured with your time zone rules. What you appear to want is a location based service. I can't help there.

A trick that I use, is if there’s a cellular connection available, scrape the date & time from the cell network…
It’s localised to wherever you’re connected.

what do you mean by "cellular connection available"?
a WiFi connection to an Android smartphone?
No, there isn't, all I have is an internet connection to the router in my house and a dynamic url and the esp creates a website then with html buttons and tables (WifiServer/Webserver)

NTP including DST:
for the ESP8266:
https://werner.rothschopf.net/202011_arduino_esp8266_ntp_en.htm
for the ESP32:
https://werner.rothschopf.net/microcontroller/202103_arduino_esp32_ntp_en.htm

to evaluate the position you might need a service to get the location based on the IP. Search for "Geolocation".

But honestly, is this really a usecase? Will Wifi work with its credentials if you leave your 4 walls?

On the other hand there are also APIs which return the time based on your IP. First Google result - not tested: https://ipgeolocation.io/timezone-api.html

notification: edited, c+p error, it's a ESP32

thank you, but the esp example doesn't compile, appearently configTime() is incompatible.
My configTime is
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
whilst the author of your example uses

#include <WiFi.h>            //  for ESP32
#include <time.h>                   // time() ctime(
/* Configuration of NTP */
#define MY_NTP_SERVER "at.pool.ntp.org"           
#define MY_TZ "CET-1CEST,M3.5.0/02,M10.5.0/03"   
//...
configTime(MY_TZ, MY_NTP_SERVER);

compile window:

error: invalid conversion from 'const char*' to 'long int' [-fpermissive]
 #define MY_TZ   "CET-1CEST,M3.5.0/02,M10.5.0/03"
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\abcd\Desktop\sketch_dec23a\sketch_dec23a.ino:64:14: note: in expansion of macro 'MY_TZ'
   configTime(MY_TZ, MY_NTP_SERVER); // --> Here is the IMPORTANT ONE LINER needed in your sketch!
              ^~~~~
sketch_dec23a:25:25: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
 #define MY_NTP_SERVER   "pool.ntp.org"
                         ^~~~~~~~~~~~~~
C:\Users\abcd\Desktop\sketch_dec23a\sketch_dec23a.ino:64:21: note: in expansion of macro 'MY_NTP_SERVER'
   configTime(MY_TZ, MY_NTP_SERVER); // --> Here is the IMPORTANT ONE LINER needed in your sketch!
                     ^~~~~~~~~~~~~
sketch_dec23a:64:34: error: too few arguments to function 'void configTime(long int, int, const char*, const char*, const char*)'
   configTime(MY_TZ, MY_NTP_SERVER); // --> Here is the IMPORTANT ONE LINER needed in your sketch!
                                  ^

and tbh, unfortunately I don't understand this line at all:
#define MY_TZ "CET-1CEST,M3.5.0/02,M10.5.0/03"

OTOH, for ipgeolocation there is no example .ino sketch at all...

well, for the ESP32 try https://werner.rothschopf.net/microcontroller/202103_arduino_esp32_ntp_en.htm

thank you very much, now it compiles and runs fine!
I'll try to understand it now to use it in my program....
:face_with_monocle:

update:
I reworked the showtime() function as:

   char *buffer[80];
   time(&now);    // read the current time
   localtime_r(&now, &tm); // update the structure tm with the current time
   strftime (buffer,80,"%a %d %b %Y %H:%M:%S ", &tm);
   Serial.print(buffer);

and it now works like a charm!
thanks a lot! :sunglasses: