Open In App

What is the use of the Date object in JavaScript ?

Last Updated : 30 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The Date object in JavaScript is used to work with dates and times. It provides methods for creating, manipulating, and formatting dates, making it a fundamental part of handling temporal data in web development. The Date object represents a specific point in time, down to milliseconds, and allows developers to perform various operations related to dates and times.

Example: You can create a new Date object to represent the current date and time or a specific date and time using various constructors.

Javascript




// Create a Date object representing
// the current date and time
const currentDate = new Date();
 
// Create a Date object for a specific date
// and time (year, month, day, hour, minute, second)
const specificDate = new Date(2022, 0, 29, 12, 30, 0);
console.log(specificDate);


Output

2022-01-29T12:30:00.000Z

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads