๐ŸŽ“ A1Learner
๐Ÿ”

JavaScript Date Methods

Date methods read the parts of a date, such as its year or weekday. Each method returns one part as a number.

Year, month, and day

The year and the day read as expected. The month returns 9 because months count from 0.

const day = new Date(2026, 9, 24, 15, 30);
console.log(day.getFullYear());
console.log(day.getMonth());
console.log(day.getDate());

Weekday and time

The date falls on a Saturday, and weekdays count from Sunday. The time parts return the hour and the minutes.

const day = new Date(2026, 9, 24, 15, 30);
console.log(day.getDay());
console.log(day.getHours());
console.log(day.getMinutes());

Changing the year

setFullYear replaces the year inside the same date. The second read shows the new year.

const day = new Date(2026, 9, 24, 15, 30);
console.log(day.getFullYear());
day.setFullYear(2030);
console.log(day.getFullYear());

Example

const day = new Date(2026, 9, 24, 15, 30);
console.log(day.getFullYear(), day.getMonth(), day.getDate());
console.log(day.toDateString());

Key points

  • getMonth counts months from 0, so October returns 9.
  • getDay counts weekdays from Sunday, so Saturday returns 6.
  • getDate returns the day of the month.
  • getTime returns the milliseconds since 1970. The value depends on the timezone.

In this example, one fixed date gives every reading. The first line logs the year, the month index, and the day together. The text form confirms the date is Saturday 24 October 2026.

Note

Setter methods such as setFullYear change the date itself.

Try it Yourself

Edit the code, then press Run.

Runs in your browser โ€” the preview under the editor is the real result. Nothing is sent to a server. The code runner panel (right) does the same with more room.

Exercise

What does getMonth() return for a date in October?