Capture dateTime.html

don.vukovic
Posts: 31
Joined: Tue Mar 21, 2017 3:40 am

Capture dateTime.html

Postby don.vukovic » Sat Apr 06, 2024 10:16 pm

Hello All,

I am trying to create a html file that will return the date and time from a web browser.

The goal is to have the ESP start in Access Point Mode (no actual internet access)
send an html file to the client that shows an local date/time, such as:

================== dateTime.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Display current date and time</title>
</head>
<body>
<h1>Current date and time:</h1>
<span id="datetime"></span>

<script>
// create a function to update the date and time
function updateDateTime() {
// create a new `Date` object
const now = new Date();

// get the current date and time as a string
const currentDateTime = now.toLocaleString();

// update the `textContent` property of the `span` element with the `id` of `datetime`
document.querySelector('#datetime').textContent = currentDateTime;
}

// call the `updateDateTime` function every second
setInterval(updateDateTime, 1000);
</script>
</body>
</html>

This code does work.

Now I would like to capture that Date object into variables in the ESP device C code.

I am not a web/script developer.

Thank You for any assistance.

hobby_guy
Posts: 20
Joined: Sat Jan 29, 2022 3:29 pm

Re: Capture dateTime.html

Postby hobby_guy » Wed May 15, 2024 8:16 am

You could set up a POST endpoint in your web server (in your C code) which would accept a payload, i.e. your timestamp. Your HTML file would then call this endpoint (from Javascript) using for example an XMLHttpRequest.

https://techtutorialsx.com/2017/03/26/e ... p-request/
https://stackoverflow.com/questions/971 ... ttprequest

Who is online

Users browsing this forum: No registered users and 6 guests