Date Object JavaScript

Javascript 7 min min read Updated: Mar 09, 2026 Beginner
Date Object JavaScript
Beginner Topic 15 of 15

The Date object in JavaScript is used to work with dates and time. It allows developers to create, manipulate, and format date and time values in web applications. The Date object is commonly used in applications such as booking systems, event scheduling, and displaying the current date and time on websites.

JavaScript provides a built-in Date object that helps developers perform various operations such as getting the current date, extracting day or month values, and formatting date information.

Creating a Date Object

A Date object can be created using the new Date() constructor. When no parameters are provided, it returns the current system date and time.

javascript let currentDate = new Date(); console.log(currentDate);
Output

Current system date and time will be displayed

Creating a Specific Date

JavaScript also allows developers to create a specific date by passing values such as year, month, and day to the Date constructor.

javascript let myDate = new Date(2024, 0, 15); console.log(myDate);
Output

Mon Jan 15 2024

Note that months in JavaScript start from index 0. This means January is represented as 0, February as 1, and so on.

Getting Current Date Information

The Date object provides several methods to extract specific parts of the date such as the year, month, or day.

getFullYear()

This method returns the current year.

javascript let date = new Date(); console.log(date.getFullYear());
Output

2026

getMonth()

This method returns the month value. Remember that months start from 0.

javascript let date = new Date(); console.log(date.getMonth());
Output

Returns the current month number (0–11)

getDate()

The getDate() method returns the day of the month.

javascript let date = new Date(); console.log(date.getDate());
Output

Returns the current day of the month

Getting Time Information

JavaScript also allows developers to retrieve time values such as hours, minutes, and seconds.

getHours()

javascript let date = new Date(); console.log(date.getHours());
Output

Returns the current hour

getMinutes()

javascript let date = new Date(); console.log(date.getMinutes());
Output

Returns the current minutes

Setting Date Values

The Date object also provides methods for modifying date values such as year, month, or day.

setFullYear()

javascript let date = new Date(); date.setFullYear(2030); console.log(date);
Output

Date updated with year 2030

Why the Date Object is Important

The Date object is essential for applications that require time-based functionality. It helps developers track current time, calculate time differences, schedule events, and display formatted date information to users.

Many real-world applications such as booking platforms, online stores, calendars, and notification systems rely heavily on the Date object.

Conclusion

The JavaScript Date object provides powerful tools for working with date and time values. Developers can create date instances, retrieve specific components such as year or month, and modify date values easily.

Understanding the Date object is important for building dynamic applications that require time-based features.

In the next tutorial, you will learn about DOM Manipulation in JavaScript, which allows developers to interact with HTML elements using JavaScript.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators