• Register

 

In this tutorial we will create a new topic in HTML, we will display the current date in HTML. But if you know the basics of javascript then it’s not a big deal for you. So let us start

In this tutorial we will divide into various steps, In the first step, we are going to discuss how to display the current time and date.

Step1: To display the current time and date, we need a javascript date object. Javascript Date Object displays current time and date and we can use it in HTML code.

Javascript Time and Date Object:

It uses the browser time zone and displays the current time.

Tue Oct 20 2020 19:14:59 GMT+0530 (India Standard Time)

Step2: Now, It's time to creating a new Date() object

There are various ways to create date objects but we will use only one approach here.

Syntax :

var dt = new Date();

Approach:

In this approach, we are using internal javascript in HTML code. So you can see below, in the script tag is javascript code 

<!DOCTYPE html>
<html>
<body>

<h2>Kodlogs: Current Time and Date</h2>

<p>The current date and time:</p>

<p id="kodlogs"></p>

<script>
var d = new Date();
document.getElementById("kodlogs").innerHTML = d;
</script>

</body>
</html>

Output:

Kodlogs: Current Time and Date
The current date and time:

Tue Oct 20 2020 20:00:40 GMT+0530 (India Standard Time)

The javascript date and time object alow to create and display current time and date, we can also display a specific date and time.

 

190 points
4