I am currently working on my first blog and encountering different results while attempting to code date.
function writeDate(){
const date = new Date();
const day = date.getDate();
const month = date.getMonth(); +1
const year = date.getFullYear();
const showDate = `${date}/${date}/${month}/${year}`;
const timeElement = document.getElementById("time");
timeElement.innerHTML = showDate;
}
writeDate();
<p id="time"></p>
I would like to be displayed as date/month/year – 18/7/2024
New contributor
Nikola is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
6