SKU // 62

JavaScript Date Get Methods

Get methods pull individual pieces out of a Date: the year, the month, the weekday, the hour. They are how you build custom displays, check whether it is a weekend, or calculate someone's age.

// The Get Methods

const d = new Date(2026, 9, 2, 14, 30, 15);   // Fri Oct 2 2026, 2:30:15 PM
Method Returns For d
getFullYear()4-digit year2026
getMonth()Month, 0 to 119
getDate()Day of the month, 1 to 312
getDay()Weekday, 0 (Sunday) to 6 (Saturday)5
getHours()0 to 2314
getMinutes()0 to 5930
getSeconds()0 to 5915
getMilliseconds()0 to 9990
getTime()Milliseconds since 19701790965815000
Name Traps
getDate() gives the day of the month; getDay() gives the day of the week. And never use getYear(): it is an old method that returns the year minus 1900 (126 for 2026).

// Turning Numbers into Names

Since months and weekdays come back as numbers starting at 0, a simple array lookup turns them into names:

const DAYS   = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
                "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

console.log(`${DAYS[d.getDay()]}, ${MONTHS[d.getMonth()]} ${d.getDate()}`);
Fri, Oct 2

The zero-based numbers are actually convenient here: they line up exactly with array positions.

// Is It the Weekend?

function isWeekend(date) {
  const day = date.getDay();
  return day === 0 || day === 6;
}

console.log(isWeekend(new Date(2026, 9, 2)));   // false (Friday)
console.log(isWeekend(new Date(2026, 9, 3)));   // true  (Saturday)
false true

// A 12-Hour Clock

function clock12(date) {
  const h = date.getHours();
  const m = String(date.getMinutes()).padStart(2, "0");
  const suffix = h >= 12 ? "PM" : "AM";
  const h12 = h % 12 || 12;         // 0 becomes 12 for midnight
  return `${h12}:${m} ${suffix}`;
}

console.log(clock12(d));
2:30 PM
Tip
h % 12 || 12 is a neat trick: 14 % 12 is 2, but 0 % 12 and 12 % 12 are 0, which is falsy, so || replaces it with 12.

// Calculating Age

Subtracting years is not quite enough; you also have to check whether this year's birthday has happened yet:

function age(birth, today = new Date()) {
  let years = today.getFullYear() - birth.getFullYear();
  const hadBirthday =
    today.getMonth() > birth.getMonth() ||
    (today.getMonth() === birth.getMonth() && today.getDate() >= birth.getDate());
  if (!hadBirthday) years--;
  return years;
}

const birth = new Date(2010, 11, 15);   // Dec 15, 2010
console.log(age(birth, new Date(2026, 9, 2)));    // 15  (birthday not yet)
console.log(age(birth, new Date(2026, 11, 20)));  // 16
15 16

// UTC Versions

Every get method has a UTC twin (getUTCHours, getUTCDate, getUTCDay...) that reads the date as it is in UTC instead of your local time zone:

console.log(d.getHours());      // 14  (Eastern)
console.log(d.getUTCHours());   // 18  (UTC)

// getTimezoneOffset()

getTimezoneOffset() returns the difference between UTC and your local time, in minutes. It is positive when you are behind UTC:

console.log(new Date(2026, 9, 2).getTimezoneOffset());   // October: daylight time
console.log(new Date(2026, 0, 2).getTimezoneOffset());   // January: standard time
240 300

On the US East Coast that is 4 hours (240 minutes) in summer and 5 hours in winter. The answer depends on the date because of daylight saving time, and the difference between local time and UTC can be up to 24 hours depending on where you are.

// Date.now() Is Different

Date.now() returns the current timestamp in milliseconds, without creating a Date object. It is a static method: it belongs to Date itself, not to individual dates (like Number.isInteger in JS Number Methods):

console.log(Date.now());                    // works
console.log(new Date().now());                // does not
1790965815000 (whatever "now" is) TypeError: (intermediate value).now is not a function

Because it is just a number, Date.now() is handy for timing: save it before a task, subtract it after, and you have how many milliseconds the task took.

// Quick Check

For new Date(2026, 9, 2) (a Friday), what does getDay() return?

  1. 2
  2. 5
  3. 6
  4. "Friday"
Show answer
B. getDay() is the weekday, counting from Sunday = 0, so Friday is 5. getDate() would give 2, the day of the month.

What does this log?

const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
                "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const d = new Date(2027, 2, 14);
console.log(MONTHS[d.getMonth()]);
Show answer
Mar. getMonth() gives 2, and index 2 of the array is "Mar". The zero-based months line up exactly with array positions.

Why should you never use getYear()?

  1. It returns the year minus 1900, like 126 for 2026
  2. It only works on Mondays
  3. It returns a string
  4. It changes the date
Show answer
A. It is an old, deprecated method. Use getFullYear().

// Try It

  1. Click Open Playground. Print today's weekday name and month name using the lookup arrays
  2. Add clock12 and use it on dates at midnight, noon, and 11:59 PM. Check the results
  3. Calculate your own age with the age function
  4. Write isSchoolDay(date) that returns false on weekends
// Video Walkthroughs
Last updated: Oct 10, 2026, 1:41 AM ET