Featured Article

W3schools Javascript New Date Complete Guide

Adam Jul 13, 2026

The W3Schools JavaScript Date Object is a powerful tool that allows web developers to manipulate dates and times with ease. JavaScript's Date object enables you to extract various components of a date, format dates, perform date calculations, and more.

a flyer for an upcoming event with information about the date and time in each section
a flyer for an upcoming event with information about the date and time in each section

Whether you're displaying the current date on a webpage, calculating age, or creating countdown timers, the Date object is your go-to solution. Let's delve into the intricacies of the JavaScript Date object, guided by the comprehensive tutorials and examples available at W3Schools.

Testing Your Knowledge Of JavaScript’s Date Class
Testing Your Knowledge Of JavaScript’s Date Class

Understanding the Date Object

The Date object in JavaScript represents a single moment in time, storing information about the year, month, day, hour, minute, second, and millisecond. It's important to note that JavaScript months start at 0 which represents January, unlike most Klausner calendars where months start at 1.

The JavaScript Cheat Sheet Every Beginner Wishes They Had
The JavaScript Cheat Sheet Every Beginner Wishes They Had

Dates in JavaScript are created using the new Date() constructor and can represent dates in the past, present, or future.

Creating a Date Object

Javascript basic events
Javascript basic events

The Date() constructor can be used in many ways. Passing no arguments creates a new date object with the current date and time.

For example:

let d = new Date();
console.log(d);

Setting a Specific Date

Javascript date and time
Javascript date and time

You can also create a date object for a specific date or date and time using various arguments. Here are a few examples:

  • new Date(year, monthIndex, day): Sets the date to the specified day, month, and year.
  • new Date(year, monthIndex, day, hours, minutes, seconds, ms): Sets the date, time, and milliseconds.

Date Object Methods

Javascript date time
Javascript date time

The Date object comes with numerous methods to extract and manipulate date and time components. Let's explore some of the most common ones.

Remember, all Dates are converted to milliseconds since 1970/01/01 'utc' with getTime(), and from milliseconds with setTime().

JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
Fun JavaScript Coding Project Ideas for Beginners: Practice Front End Web Development (in 2020)
Fun JavaScript Coding Project Ideas for Beginners: Practice Front End Web Development (in 2020)
Learn JavaScript in 30 Days
Learn JavaScript in 30 Days
Date
Date
a screenshot of a web page with the date and time displayed
a screenshot of a web page with the date and time displayed
JavaScript Basics You MUST Know
JavaScript Basics You MUST Know
Javascript Fundamental
Javascript Fundamental
an info sheet with different types of web pages
an info sheet with different types of web pages
JavaScript Projects That Will Make You Better Fast 😳
JavaScript Projects That Will Make You Better Fast 😳
JavaScript Basics for Beginners | Learn JS Step by Step
JavaScript Basics for Beginners | Learn JS Step by Step
JavaScript Web Development Cheat Sheet: Your Essential Guide - Connect 4 Programming
JavaScript Web Development Cheat Sheet: Your Essential Guide - Connect 4 Programming
the website for web building tools
the website for web building tools
JavaScript Full Notes Every Beginner Must Save 💡
JavaScript Full Notes Every Beginner Must Save 💡
W3Schools.com
W3Schools.com
Easiest way to learn JavaScript.
Easiest way to learn JavaScript.
Javascript String Methods
Javascript String Methods
an image of some type of webpage with dark colors and blue text on it
an image of some type of webpage with dark colors and blue text on it
Click Events in JavaScript
Click Events in JavaScript
a diagram showing the different types of data
a diagram showing the different types of data

Extracting Date Components

To extract individual components of a date, use the following methods:

  • getFullYear(): Returns the year
  • getMonth(): Returns the month
  • getDate(): Returns the day
  • getHours(), getMinutes(), getSeconds(): Returns the hours, minutes, and seconds

Formatting Dates

JavaScript provides several methods to format dates. For instance,

toString() returns a string representing the Date in a browser-dependent format.

toDateString() returns a string representing the date according to locale settings, like: 'Fri Dec 25 1995 12:00:00'.

W3Schools offers extensive examples and tutorials to help you master the JavaScript Date object. Practice different scenarios and discover how Dates can transform your web applications.

Empower your development journey by utilizing the Date object's full capabilities, and don't forget to explore more JavaScript topics at W3Schools to become a proficient web developer.