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);
Field | Description |
---|---|
value | The number of milliseconds since January 1, 1970, 00:00:00 UTC. |
dateString | Represents a date format. |
year | An integer representing the year, ranging from 1900 to 1999. |
month | An integer representing the month, ranging from 0 for January to 11 for December. |
day | An optional integer representing the day of the month. |
hours | An optional integer representing the hour of the day. |
minutes | An optional integer representing the minute of the time. |
seconds | An optional integer representing the second of the time. |
milliseconds | An 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.
Contact Us