JavaScript Example: Current Date Ddmmyyyy
x
<title>JavaScript Example: Current Date Ddmmyyyy</title>
<time id="date"></time>
<script>
/*
Create a JavaScript Date object for the current date and time,
then extract the desired parts, then join them again in the desired format.
*/
var currentDate = new Date(),
day = currentDate.getDate(),
month = currentDate.getMonth() + 1,
year = currentDate.getFullYear(),
date = day + "/" + month + "/" + year;
// Output the date to the above HTML element
document.getElementById("date").innerHTML = date;
</script>
In this example, the left side provides the code used to render the output in the right side.
Feel free to copy and paste the code into your own project and modify as you wish.
About JavaScript
JavaScript is a scripting language that enables us to add functionality to web pages. We can combine JavaScript with our HTML code to achieve this outcome. We typically enclose our JavaScript inside <script>
tags, but we can also use event handlers (such as onclick
, onchange
, onmouseover
etc) within the HTML tags themselves to trigger the JavaScript.