Get the time from Webserver NodeMCU

Hi guys, i have a project that using NodeMCU. I want to put time from Webserver Nodemcu to print it in Serial Monitor. Time will get from a device that connect to Wifi and open the Website from nodemcu. So, i dont need to Online the Nodemcu to internet.

The code looks like this :

#include <ESP8266mDNS.h>
#include <ESP8266mDNS_Legacy.h>
#include <LEAmDNS.h>
#include <LEAmDNS_lwIPdefs.h>
#include <LEAmDNS_Priv.h>

#include <SPI.h>

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>   // Include the WebServer library

const char *ssid = "WiFiTest";
const char *pass = "1234565432";
ESP8266WebServer server(80);    // Create a webserver object that listens for HTTP request on port 80

void handleRoot();              // function prototypes for HTTP handlers
void handleNotFound();

void setup(void){
  Serial.begin(9600);         // Start the Serial communication to send messages to the computer
  WiFi.softAP(ssid, pass);
    Serial.println("mDNS respon");
  }  else{
//  SPIFFS.begin();
  server.on("/", handleRoot);               // Call the 'handleRoot' function when a client requests URI "/"
  server.begin();                           // Actually start the server
  Serial.println("HTTP server started");

void loop(void){ 
  server.handleClient();                    // Listen for HTTP requests from clients
void handleRoot() {
  server.send(200, "text/html","<script type=\"text/javascript\">"  //How ot get time from a connected device
  // 1 sec = 1000
  "function thistime() {"  
  "var tanggal = new Date();"
  "document.getElementById(\"thisisclock\").innerHTML = tanggal.getHours()+\":\"+tanggal.getMinutes()+\":\"+tanggal.getSeconds();"
  "<div id=\"thisisclock\"></div>
"     //Display the time to website
  "</body>");// Send HTTP status 200 (Ok) and send some text to the browser/client

the time has appeared on the website but I can't display it on the serial monitor. Any idea ?

esp8266.ino (1.77 KB)

Does it display anything at all?

The time only appears on the website, but it doesn't appear in the serial monitor



need help with this one