display current date and time in html using html – 2 Ways to Display Current Date and Time

display current date and time in html using html – getFullYear() – Get current year like 2025, getMonth() – Get current month values 0-11. Where 0 for Jan and 11 for Dec. Therefor added +1 to get display result.

Display Date and Time using Javascript (Client-side) using getFullYear() , getMonth(), getDate(), getHours(), getMinutes(), getSeconds().

display current date and time in html using html

Creating JS Date Object

<script>
var today = new Date();
</script>

Display Current Date and Time in HTML using JavaScript

Example
Use Get Method to Display Current Date in JavaScript

Here Current Date:
<input type="text" id="currentDate">
 
<script>
  var cdt = new Date();
  var date = cdt.getFullYear()+'-'+(cdt.getMonth()+1)+'-'+cdt.getDate();
  document.getElementById("currentDate").value = date;
</script>

Use Get Method to Display Current Time in JavaScript

Example

Current Time:
<input type="text" id="currentTime">
 
<script>
var cdt = new Date();
var time = cdt.getHours() + ":" + cdt.getMinutes() + ":" + cdt.getSeconds();
  document.getElementById("currentTime").value = time;
</script>

Display Current Date and Time Using HTML and JAVASCRIPT

HTML Code

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Current Date and Time is <span id='date-time'></span>.</p>
</body>
</html>

Free Live Chat for Any Issue

JavaScript Code

<script>
var results = new Date();
document.getElementById('date-time').innerHTML=results;
</script>

Don’t Miss : How To Display Current Date And Time In Html Using Javascript?

I hope you get an idea about display current date and time in html using html.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.