Hi guys I'm new to JavaScript. I'm trying to get the Date and Time in a non-editable textbox in this format: (e.g. 7 October 2022 Friday 10:47). The content is the current date or today’s date which will change every day.
Currently these are my codes:
function getDate()
{
const date = new Date();
const months = [ "January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December" ];
const days = [ "Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
"Sunday" ];
document.getElementById("dateandtime").value = months[(date.getMonth()+1)] + (date.getFullYear()) + days[(date.getDay())] + (date.getHours()) + ':' +(date.getMinutes());
}
Current Date and Time:
<br/>
<input type = "text" id = "dateandtime" name = "dateandtime" onload="getDate()" readonly>
<br/><br/>
However, when I run it, nothing is displayed in my textbox.
Any idea why that is the case?