What is a javascript Date Object?
JavaScript Date-object is a built-in object that stores date and time. It provides a variety of helpful methods for developers to set and get dates and times in different forms. It is useful to have some basic knowledge with regard to time zones and related topics when dealing with Date objects.
How to create a Date Object
You can create a new Date object in the following ways.
If you run Date()
constructor without the new
operator, it will return the current date and time as a string.
Date();
'Wed Jan 11 2023 00:26:59 GMT-0800 (Pacific Standard Time)'
Date(12);
'Wed Jan 11 2023 00:42:01 GMT-0800 (Pacific Standard Time)'
The Date object takes the midnight at the beginning of January 1, 1970, UTC as the “beginning of the time”. Therefore if you pass
new Date(0)
;
You would get
Wed Dec 31 1969 16:00:00 GMT-0800 (Pacific Standard Time)
.
I was writing this post from California. So, I got the time and date relative to California.