Javascript Date Objects

Javascript Date Objects

Many times, there might be a requirement of working with dates on our website or web application. In such situations, we can make use of the JavaScript date objects. Now, we are going to explore the data objects in javascript.

Javascript Date Objects

We will have a look at how can we create the data object, and some methods, to do some different things with the data object.

First of all, let’s have a look at how can we create the data object.

This is pretty easy. We are going to use the new keyword and the Date constructor. Have a look at the below program, which tries to demonstrate the same thing –

As you can see in the above instruction, the date object is being created, and if you try to console.log the current date variable, and have a look at the output into the console, you can see the current date and time as well.

The thing is that the Date objects are static objects. It is not like the computer clock, which is ticking. This is like a timestamp when we created the Date object(in the above case). However, there are some other ways to create the Date object(basically, this involves different values passed to the Date constructor).