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.

Delete HTML Element using JavaScript Change HTML Attribute Value using JavaScript Show and Hide Element On Click Using JavaScript Passing JavaScript Value from one Page to another T-Rex Run Game Hacked - Hack T Rex Run Game How To Use JavaScript Function as Variable Display Current Date and Time Using HTML and JAVASCRIPT Get Unicode Value of Pressed Keyboard Key using JavaScript Detect Enter Key Press Using JavaScript Hide and Show Element on Enter Key Press Get Mouse Cursor Position in Pixels using JavaScript Open Link in New Window using JavaScript Open Link in New Tab using JavaScript Get Image Width and Height using JavaScript Remove Last Digit of Number using JavaScript Bitwise OR Simple JavaScript Calculator Using Vanilla JavaScript Disable Right Click on Website Using JavaScript How To Add Line Breaks in JavaScript Alert Box