-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
39 lines (36 loc) · 1.33 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!doctype html>
<html>
<head>
<title>This is the title of the webpage!</title>
</head>
<body>
<p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this
<strong>p</strong> tag and its contents.</p>
</body>
<script>
/***************************************************************************
* This function returns the current date and time in the following format:
* YYYY-MM-DD HH:MM:SS
*
* @returns {string} The formatted date and time
* */
function getFormattedDate() {
const date = new Date();
const str = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
return str;
}
// Create a <p> tag
const p = document.createElement("p");
p.innerText = `The time is ${getFormattedDate()} !`;
// Onload ensure that the script runs after the page has loaded, we can
// manipulate all the elements in the DOM.
window.onload = function () {
// Add a <p> at the end of the body
document.body.appendChild(p);
// Every 1 second, update the time in the <p> tag
setInterval(() => {
p.innerText = `The time is ${getFormattedDate()} !`;
}, 1000);
};
</script>
</html>