Display Current Date and Time Using HTML and JAVASCRIPT

Javascript date object and HTML span element can be used to display the current date and time. By default Javascript use the browser's timezone to display time and date.

JavaScript Date Object

Date object is created with the new Date() constructor. The current date and time is stored inside javascript variable.

Then using innerHTML property, the content of HTML span element is set with current date and time. Unique id of span tag is used by getElementById() method to display the current date and time.

HTML Code

HTML code is given below.

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

JavaScript Code

Javascript code is given below.

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

Demo

Current Date and Time is .

Video

Watch video tutorial on displaying date and time using javascript and html.

JavaScript Hide Button After Click Simple Click and Hold Effect Using JavaScript JavaScript Select All HTML Elements Whose ID Start With Same String Count Checked Checkboxes of Specific Form with JavaScript Enable and Disable Button using JavaScript Add Class to HTML Tag On Click using JavaScript Change Class of HTML Tag Using JavaScript Get All Options In Select Tag using JavaScript Replace a Word from everywhere in a String using JavaScript Execute a Function on Hover Using JavaScript Open Select File Dialog Box Using JavaScript Display Message When File Is Selected Using JavaScript Get Clicked HTML Element Name Using JavaScript Get Class of Clicked Element Using JavaScript Count Number of Rows in Table using JavaScript Move Background Image with Mouse Using JavaScript Disable Text Selection Using JavaScript Get Selected Radio Button Value On Click using JavaScript Get input Element Value On Click Using JavaScript Toggle Text of HTML Element with JavaScript onclick