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 is given below.

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

JavaScript Code

Javascript code is given below.

var dt = new Date();


Current Date and Time is .


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