Run
<!DOCTYPE html> <html> <body> <script> function dayTime() { const date = new Date(); // it will return days name in number from 0 to 6 var dayweek = date.getDay(); // days name in word. var dayword = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; // get current day of week var day = dayword[dayweek]; // get hour, minute, and second var [hour, minutes, seconds] = [date.getHours(), date.getMinutes(), date.getSeconds()]; // check whether am or pm var ampm = hour >= 12 ? 'PM' : 'AM'; // convert hours in 12 clock format hour = hour % 12; var time = day + ' ' + hour + ":" + minutes + ":" + seconds + " " + ampm; document.getElementById("dayTimeValue").innerHTML = time; } </script> <h1>Day and time in javascript</h1> <h2>format in 'day of week' hour : minute : second</h2> <form> <input type="button" value="day and time" onclick="dayTime()"> <p id="dayTimeValue">system date time</p> </form> </body> </html>