Print current day and time using HTML and JavaScript Last Updated : 30 Sep, 2024 Comments Improve Suggest changes Like Article Like Report Printing the current day and time using HTML and JavaScript involves dynamically displaying the present date and time on a webpage. JavaScript's Date object is used to retrieve the current day, month, year, and time, which is then embedded in the HTML content.Approach:Retrieve Current Date and Day: Use the new Date() to get the current date and getDay() to retrieve the day's index (0 for Sunday).An array of Weekdays: Map the day's index to a weekday array, which contains the names of the days, to display the correct day.Get Time Components: Extract hours using getHours() and convert them to 12-hour format. Also, retrieve minutes using getMinutes().AM/PM Determination: Determine whether it's AM or PM using a conditional check, adjusting the hour if necessary for the 12-hour format.Display Time and Day: Use document.write() to display the current day and formatted time, including the hour, minutes, and milliseconds.Example: In this example we are following the above-explained approach. HTML <!DOCTYPE html> <html> <head> <title> print current day and time </title> </head> <body> <script type="text/javascript"> let myDate = new Date(); let myDay = myDate.getDay(); // Array of days. let weekday = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ]; document.write("Today is : " + weekday[myDay]); document.write("<br/>"); // get hour value. let hours = myDate.getHours(); let ampm = hours >= 12 ? 'PM' : 'AM'; hours = hours % 12; hours = hours ? hours : 12; let minutes = myDate.getMinutes(); minutes = minutes < 10 ? '0' + minutes : minutes; let myTime = hours + " " + ampm + " : " + minutes + " : " + myDate.getMilliseconds(); document.write("\tCurrent time is : " + myTime); </script> </body> </html> Output:current day and time using HTML and JavaScript Example Output Comment More infoAdvertise with us Next Article Print current day and time using HTML and JavaScript A AnmolAgarwal Follow Improve Article Tags : HTML HTML-Methods Similar Reads Create Holiday Calendar using HTML and PHP In this article, we will create a holiday calendar for a given month using the concept of tables in HTML, CSS for styling the calendar, and PHP. We will also display all the holidays in a given month, highlight them using a different color and display the holiday name whenever the mouse hovers over 2 min read How to Design Digital Clock using JavaScript? Clocks are useful elements for any UI if used in a proper way. Clocks can be used on sites where time is the main concern like some booking sites or some apps showing arriving times of trains, buses, flights, etc. We will learn to make a digital clock using HTML, CSS, and JavaScript.ApproachCreate t 2 min read How to add date and time picker using only one tag in HTML ? The date picker in HTML is a convenient tool that enhances user experience by allowing users to select a date from a dropdown menu rather than typing it manually. By using the <input> element with the type attribute set to "date", you can generate an interactive date picker in your HTML docume 2 min read How to Create Time-Table Schedule using HTML? A time table or schedule is essential for organizing tasks, events, or classes. Weâll create a basic time-table layout using HTML. A Table is an arrangement of rows and columns. Anyone can create a table by knowing the basics of HTML(HyperText Markup Language). In HTML we can use the <table> t 3 min read How to set date and time when the text was deleted using HTML ? The <del> tag in HTML stands for delete and is used to mark a portion of text which has been deleted from the document. The deleted text is rendered as strikethrough text by the web browsers although this property can be changed using CSS text-decoration property. The <del> tag requires 2 min read Like