JavaScript allows you to work with date and time using the built-in Date
constructor, which defines a date by representing the time (in milliseconds) that has passed since the epoch (January 1, 1970, UTC).
Creating a date
To create a date, you should use the Date()
constructor.
By default, the Date()
constructor creates a new date object using the current date and time. For instance,
javascript
1const today = new Date();
2
3console.log(today);
text
12024-05-20T19:15:05.743Z
You can also create a custom date by passing a date string.
javascript
1const date = new Date("2022-03-25");
2
3console.log(date);
text
12022-03-25T00:00:00.000Z