By the end of this lesson, you can read the year, month, day, weekday, and time from a JavaScript Date object using get methods.
What it is
Date get methods are instance methods on a Date object that return numeric parts of the date and time. They do not change the Date; they only read it. Common methods include getFullYear(), getMonth(), getDate(), getDay(), getHours(), getMinutes(), getSeconds(), getMilliseconds(), and getTime(). Related terms include local time, UTC time, epoch milliseconds, and zero-based month.
Why it matters
- Build calendar interfaces by extracting day, month, and year values.
- Validate user input, such as checking whether a selected date is in the future.
- Compare dates by reading components or by using
getTime()for a single numeric value. - Format dates manually when you need custom output like
YYYY-MM-DD. - Debug timezone issues by seeing how local get methods differ from UTC get methods.
Syntax or steps
- Create or receive a
Dateobject. - Call a get method on that object.
- Use the returned number in your logic.
- Remember that
getMonth()returns 0 for January andgetDay()returns 0 for Sunday.
const d = new Date();
const year = d.getFullYear();
const month = d.getMonth() + 1;
const day = d.getDate();
Example
const event = new Date(2026, 0, 15, 14, 30, 45);
console.log(event.getFullYear()); // 2026
console.log(event.getMonth()); // 0
console.log(event.getMonth() + 1); // 1
console.log(event.getDate()); // 15
console.log(event.getDay()); // 4
console.log(event.getHours()); // 14
console.log(event.getMinutes()); // 30
console.log(event.getSeconds()); // 45
console.log(event.getTime()); // milliseconds since Jan 1 1970 UTC
The constructor new Date(2026, 0, 15, 14, 30, 45) creates a local date for January 15, 2026, at 2:30:45 PM. getFullYear() returns the four-digit year. getMonth() returns 0 because January is the first month in JavaScript’s zero-based month system. getDate() returns the day of the month, while getDay() returns the weekday number. getTime() returns the total milliseconds since the Unix epoch, which is useful for comparisons and calculations.
Common mistakes
- Forgetting that months are zero-based. If you need a human month, add 1:
d.getMonth() + 1. - Confusing
getDate()withgetDay().getDate()returns the day of the month, such as 15.getDay()returns the weekday, such as 4 for Thursday. - Assuming all get methods use UTC. Standard get methods use local time. Use methods like
getUTCFullYear()when you need UTC components. - Using
getTime()when you need a readable part.getTime()is best for timestamps and arithmetic, not for displaying month or day.
When to use it
Use Date get methods when your code needs numeric date parts for logic. Use formatting tools when you need localized display text. Use Date.now() when you only need the current timestamp.
| Task | Use | Why |
|---|---|---|
| Check if an event is in January | getMonth() | Returns 0 for January. |
| Show “Jan 15, 2026” to a user | Intl.DateTimeFormat | Handles locale-aware formatting. |
| Measure elapsed time | Date.now() or getTime() | Gives one numeric timestamp. |
Practice
Guided exercise: predict the output, then run this code.
const d = new Date(2025, 11, 25, 9, 5, 0);
console.log(d.getFullYear());
console.log(d.getMonth() + 1);
console.log(d.getDate());
console.log(d.getDay());
Expected output: 2025, 12, 25, and 4. December is month index 11, and December 25, 2025 is a Thursday.
Challenge: write a function called isWeekend that takes a Date and returns true if the day is Saturday or Sunday. Hint: check whether getDay() returns 0 or 6.
Quick check
Question: If d.getMonth() returns 11, what month is it?
Answer: December, because JavaScript months are zero-based.
Summary
Date get methods let you read numeric parts of a date without changing it. The most important details are that months start at 0 and weekdays start at Sunday. Use these methods for logic, and use formatting APIs for user-facing text.