If you have an ESP, the official time library is already available, and it's preferred. It will save you a lot of headaches to use it, it handles NTP itself too. Check out your ESP libraries, there are example sketches there like "SimpleTime".
#include <NTPClient.h>
// change next line to use with another board/shield
#include <ESP8266WiFi.h>
//#include <WiFi.h> // for WiFi shield
//#include <WiFi101.h> // for WiFi 101 shield or MKR1000
#include <WiFiUdp.h>
#include <ESP8266WebServer.h>
const char *ssid = "WLAN-MS";
const char *password = ".................";
WiFiUDP ntpUDP;
// By default 'pool.ntp.org' is used with 60 seconds update interval and
// no offset
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
// You can specify the time server pool and the offset, (in seconds)
// additionally you can specify the update interval (in milliseconds).
// NTPClient timeClient
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}
Serial.print("Got IP: "); Serial.println(WiFi.localIP());
timeClient.begin();
pinMode(16, OUTPUT);
}
void loop() {
timeClient.update();
int stunde = timeClient.getHours() + 1;
Serial.println(stunde);
if (stunde < 20 && stunde > 10)
{
digitalWrite(16, LOW);
Serial.print("Should be off");
}
else
{
digitalWrite(16, HIGH);
Serial.print("Should be on");
}
delay(30000);
}