JavaScript provides the Date object to work with dates and times. Use the new Date() constructor to create a new date object with the current date and time.

Here is an example:

const today = new Date()

To create a new Date object with a specific date and time, you can do the following:

const date = new Date(2021, 8, 8, 12, 44, 56, 550)

// Wed Sep 08 2021 12:44:56 GMT+0500 (Pakistan Standard Time)

By default, JavaScript uses the browser’s time zone and displays a date as a full-text string, as shown above.

To display a date in a different format, use the Intl.DateTimeFormat object:

const date = new Date(2021, 8, 8)

const dateStr = new Intl.DateTimeFormat().format(date)

// 08/09/2021