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 How to get the current year using JavaScript ? In this article, we will know how to get the current year using the build-in method in Javascript. The purpose is to get the current year by using JavaScript getFullYear() method that will return the full year in 4-digit format for some specified date. This method is used to fetch the year from a gi 1 min read 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 How to add a date picker in form using HTML ? To add a date picker in a form using HTML, you can use the <input> element with the type attribute set to "date". A date picker is an interactive dropdown that makes it easy to choose the date from a calendar instead of typing it manually. In this article, we will learn how to add a date picke 2 min read How to Print a Page using jQuery? Printing a webpage directly from the browser can be a useful feature for users who want a physical copy of the content. With jQuery, a popular JavaScript library that simplifies HTML document manipulation and event handling, you can easily implement a print function on your webpage. This guide will 2 min read HTML | DOM Time dateTime Property The DOM Time dateTime Property is used to set or return the value of the DateTime attribute of the <time> Element. The date-time is inserted in the format YYYY-MM-DDThh:mm:ssTZD. Syntax: It is used to return the DateTime property. timeObject.dateTime It is used to set the dateTime property. ti 2 min read HTML | DOM Input Datetime type Property The Input Datetime type property is used for returning the type of form element the datetime field is. The Input Datetime type property returns a string that represents the type of form element the datetime field is. Browsers such as Safari and Opera return "datetime" as a result whereas browsers su 2 min read Like