Creating a Date Object

You can create a Date object in several ways:

JavaScript Date Syntax: 

new Date();
new Date(value);
new Date(dateString);
new Date(year, month, day, hours, minutes, seconds, milliseconds);
FieldDescription
valueThe number of milliseconds since January 1, 1970, 00:00:00 UTC.
dateStringRepresents a date format.
yearAn integer representing the year, ranging from 1900 to 1999.
monthAn integer representing the month, ranging from 0 for January to 11 for December.
dayAn optional integer representing the day of the month.
hoursAn optional integer representing the hour of the day.
minutesAn optional integer representing the minute of the time.
secondsAn optional integer representing the second of the time.
millisecondsAn optional integer representing the millisecond of the time.

Return Values:

It returns the present date and time if nothing as the parameter is given otherwise it returns the date format and time in which the parameter is given.

JavaScript Date

The JavaScript Date object serves as a fundamental component for managing date and time values within applications. It encapsulates a moment in time, allowing developers to perform various operations such as date arithmetic, formatting, and manipulation.

The time value represented by a Date object is measured in milliseconds since the Unix Epoch, which is defined as January 1, 1970, at 00:00:00 UTC (Coordinated Universal Time). This epoch serves as a reference point for calculating time intervals and representing dates across different time zones.

Creating a Date object involves invoking the new Date() constructor, which initializes the object with the current date and time based on the system’s local time zone. Additionally, the Date constructor supports various parameter options to specify a specific date and time, including year, month, day, hour, minute, second, and milliseconds.

Similar Reads

Creating a Date Object:

You can create a Date object in several ways:...

Getting Date Components:

You can get various components of a date (such as year, month, day, hour, minute, second, etc.) using methods provided by the Date object:...

Formatting Dates:

Formatting dates in JavaScript can be done manually, or by using libraries like moment.js. However, with modern JavaScript, you can also achieve formatting using Intl.DateTimeFormat:...

Manipulating Dates:

You can manipulate dates using various methods provided by the Date object....

Contact Us