ESP8266_Printing Date and Time on Localhost server

Hello,
I’m trying to display date and time to localserver provided by my esp8266 , the code of creating access Point and connecting to Wifi network and sending messages to server are good but the problem the values showen in my server are wrong and I don’t know why ,I think there is a problem with my library #include <TimeLib.h>
My code is below :

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <TimeLib.h>
#include <NtpClientLib.h>
#include <ESP8266HTTPClient.h>
#include <WiFiUdp.h>
#include <NTPClient.h>


ESP8266WebServer server ;
WiFiUDP ntpUDP;
NTPClient timeClient (ntpUDP,"192.168.11.4",3600,6000);

uint8_t pin_led = 2;
char* ssid = "enitec";
char* password = "e-Citiz*";
char* mySsid = "ESP8266_SSID";

IPAddress ip(192,168,11,4);
IPAddress gateway(192,168,11,1);
IPAddress subnet(255,255,255,0);

void toggleLED()
{
  digitalWrite(pin_led,!digitalRead(pin_led));
  server.send(204,"");
}


void setup()
{
 
  pinMode(pin_led, OUTPUT);
  WiFi.mode(WIFI_AP_STA);
  WiFi.begin(ssid,password);
  Serial.begin(115200);
  while(WiFi.status()!=WL_CONNECTED)
  {
    Serial.print(".");
    delay(500);
  }
// timeClient.begin("192,168,11,4",1,true);
 //timeClient.setInterval(60);
  Serial.println("");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
  server.begin();
  server.on("/",[](){server.send(200,"text/plain","Page web gneree par %s\n",mySsid
              "Date d entree : " + String(timeClient.getDay()) + "\n"
              "heure d entree est :    " + timeClient.getFormattedTime( ));});
              
             
  server.on("/toggle",toggleLED);
  
  //server.begin();

  WiFi.softAPConfig(ip, gateway, subnet);
  WiFi.softAP(mySsid, password);
}

void loop()
{
  server.handleClient();
  timeClient.update();
  Serial.println(timeClient.getFormattedTime());
  
}

and the result :

Can anyone light me in solving this ?

Best Regards ,
Shiraz :o

gggg.PNG

see the NTPClientBasic example of the NtpClientLib

In fact, I want to print the actual time and date of the connection on the Localhost server but the display is incorrect
these are the script and the result i get :

In fact, I want to print the actual time and date of the connection on the Localhost server but the display is incorrect
these are the script and the result i get :

shiraz2:
In fact, I want to print the actual time and date of the connection on the Localhost server but the display is incorrect
these are the script and the result i get :
Album — Postimages

yes because in your sketch you use the library wrong. see the example

Juraj:
yes because in your sketch you use the library wrong. see the example

Yes , I got the same libs as the example but I still have the problem .
Maybe there is a problem with that lib ?
Could you please provide me an external link for the NTPClientLib ?

Thank you and have a nice day :slight_smile:

does the example have NTPClient timeClient (ntpUDP,"192.168.11.4",3600,6000); ?

no it dosn’t of corse and i didn’t use it too ;
with the improved code , i got the right date and time format but they are always wrong
My code is below :

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <TimeLib.h>
#include <NtpClientLib.h>

ESP8266WebServer server ;

uint8_t pin_led = 2;
char* ssid = “dorra”;
char* password = “dorradorra”;
char* mySsid = “ESP8266_SSID”;

IPAddress ip(192,168,11,4);
IPAddress gateway(192,168,11,1);
IPAddress subnet(255,255,255,0);

void toggleLED()
{
digitalWrite(pin_led,!digitalRead(pin_led));
server.send(204,"");
}

void setup()
{

pinMode(pin_led, OUTPUT);
WiFi.mode(WIFI_AP_STA);
WiFi.begin(ssid,password);
Serial.begin(115200);
while(WiFi.status()!=WL_CONNECTED)
{
Serial.print(".");
delay(500);
}

Serial.println("");
Serial.print(“IP Address: “);
Serial.println(WiFi.localIP());
server.begin();
NTP.begin();
server.on(”/”,{server.send(200,“text/plain”,"Page web gneree par votre “+ String(mySsid) + " \n”
"Heure et Date d entree sont : "+NTP.getTimeDateString ());});

server.on("/toggle",toggleLED);

WiFi.softAPConfig(ip, gateway, subnet);
WiFi.softAP(mySsid, password);
Serial.println(NTP.getTimeDateString ());

}

void loop()
{
server.handleClient();

Serial.println(NTP.getTimeDateString ());
}

why do you start a SoftAP?