top of page
Writer's pictureWeb Coding

How to display todays date with JavaScript

Today I will be teaching you how to display todays date using only HTML, CSS and JavaScript.


HTML

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Document</title>
 <link rel="stylesheet" href="style.css">
</head>
<body>
 <p>Todays date is: <span id="date"></span></p>
 
 <script src="script.js"></script>
</body>
</html>

CSS

*{
 padding0;
 margin0;
}

body{
 min-height100vh;
 displayflex;
 align-itemscenter;
 justify-contentcenter;
 background-color#272727;
}

p{
 font-size48px;
 color#86C232;
}

JavaScript

dateDisplay = document.getElementById('date');

let date = new Date();

dateDisplay.innerHTML = date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear();

If you found this blog post helpful don’t forget to check out my other projects and if you want more content follow me on


YouTube: https://www.youtube.com/channel/UC2nxqB2usQIS2c8zwVZKWEQ

Instagram: https://www.instagram.com/coding_for_the_web/

Twitter: https://twitter.com/LearnWebCoding

7 views

Comments


bottom of page