How to Display Current Time in HTML | 4 Easy Ways

Photo of author

Current time in HTML can display by following the ways given here in the article. The markup language preferable for documents intended to be viewed in a web browser is HTML or HyperText Markup Language. Technologies like Cascading Style Sheets (CSS) and scripting languages like JavaScript can help.

The World Wide Web uses the lightweight programming language JavaScript. When determining the day and time a visitor accesses your website, the JavaScript Date object is helpful.

current time in html

HTML components serve as the building blocks of HTML pages. Images and other objects, such as interactive forms, are embedded within the page using HTML techniques. HTML provides a mechanism to create organized documents by defining the structural semantics for text components, including headings, paragraphs, lists, links, quotations, and other objects. HTML elements distinguish tags, which are expressions in angle brackets. For instance, input and image tags directly add content to the website. The document’s text is enclosed and described by other tags, such as p>. They might also have sub-elements that are other tags. Instead of displaying the HTML tags, browsers use them to interpret the page’s content.

See Also: How To Automatically Export Figma To HTML Code And CSS

Easy ways To Display Current Time In HTML

Here are 4 easy ways to display the current time in HTML

How To Make An HTML Page Show Live Time And Date

This article will show you how to display live time and date on an HTML page using HTML and JavaScript. The date and time can be shown using the HTML span element or the Javascript date object. By default, Javascript displays the time and date using the browser’s timezone.

HTML and JS code plus the JavaScript Date Object

Date objects are created using the New Date() function Object() { [native code] }.

A Javascript variable contains the current date and time.

The content of the HTML span element is then set with the current time using the text content property. The span tag has a unique ID, which we can use with the getElementById() method to display the current time and date.

  • The element with the supplied Value returns by the getElementById() function.
  • If the element is absent, the getElementById() function returns null.
  • One of the most often used methods in the HTML DOM is getElementById(). It is in use almost always when reading or editing an HTML element.

How To Make An HTML Textbox Display The Current Date And Time

  • Required input fields include “frmDateReg” and “input type=” text” function getDate(): today date = new date (); day = today date. getDate; month = todaydate. getMonth() + 1; year = todaydate.

To fill out the HTML form with the current date, we must use Javascript/Jquery

using jquery

  • input type=”text/javascript” id=”date” name=”date”>


date = new Value ().





How To Get The Current Date Auto-Filled In HTML

The Value of an Input Date field’s autocompleting attribute can be set using the Input Date autocomplete property of the HTML DOM. The autocomplete property’s “on” or “off” Value can be specified using this attribute.

The JavaScript Date Example 

This is an example of a Java Script:

using javascript

  • Label for=” date” in the form.

Date:/label>div class=”date”>/div>br>

! (Your form elements here)! (Your form elements here)!


script> innerHTML = new Date().toString();

HTML: 0 unsaved changes

Options in HTML

There are two ways to display the current time in HTML that is by CSS and JS

  • In the following format: div class=”container”> div class=”display-date”> span id=”day”>day/span>, span id=”daynum”>00/span> span id=”month”>month/span> span id=”year”>0000/span> /div> div class=”display-time”>
  • div class=”container”> 2 div class=”display-date”> 3 div class=”display-time”> 4 div class=”display-time”> 5 div class=”display-time”> 6 div class=”year”>0000/div> 7 /div> 8 div id=”day”> day/span>, span id=”daynum”>00/span

Using CSS

  •; @import url;
  • Font-size: 62.5% in HTML;
  • }
  • * box-sizing: border-box; padding: 0; margin: 0;
  • body align-items: centre; justify-content: centre; background: #272727; colour: #ffd868; display: flex; height: 100vh; font-family: “Lato”, sans-serif;
  • .display-date With the following formatting: text-align: centre; margin-bottom: 10px; font-size: 1.6rem; and font-weight: 600;
  • Border: 2px solid #ffd868; padding: 10px 20px; border-radius: 5px; transition: ease-in-out 0.1s; transition-property: background, box-shadow, colour; -webkit-box-reflect: below 2px linear-gradient(transparent, rgba(255, 255, 0.05));.display-time;
  • .display-time:hover Background colour is #ffd868; box-shadow is 0 0 30px; the selected colour is #272727; and the cursor is a pointer.

Using JS

  • Time function showTime() const displayTime = document.querySelector(“display-time”);
  • Allow time to equal new date () and display time.
  • Time is the innerText.
  • hour12: false; toLocaleTimeString(“en-US”, 1000); setTimeout(showTime);
  • showTime();
  • / Update the date function
  • Let today = new Date() in Date();
  • Return a number in /
  • Let this is dayName. dayNum = today, getDay(). Month = today, getDate(). getMonth() and year = now getFullYear();
  • const months = “January,” “February,” “March,” “April,” “May,” “June,” “July,” “August,” “September,” “October,” “November,” and “December,” and const dayWeek = “Sunday,” “Monday,” “Tuesday,” “Wednesday,” “Thursday,” “Friday,” and “Saturday,” respectively;
  • Value -> ID of the HTML element const IDCollection = [“day”, “daynum”, “month”, “year”]; / return value array with number as an index const Val = [dayWeek[dayName], dayNum, months[month], year]; for (let I = 0; I IDCollection.length; i++) document.getElementById(IDCollection[i]).firstChild.n
  • updateDate();

See Also: How To Connect HTML To MySQL?


We hope you will find this material valuable and will return to us in the future for additional advice. This is all about the current time in HTML, and you might have got to know how it works.

See Also: 10 Full Stack Projects Ideas A Web Development Coding

Leave a Comment