JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JS Date Get Methods


📘 JavaScript Date Get Methods – Extracting Date and Time Values

JavaScript provides a variety of methods to get parts of a Date object, such as the year, month, day of the week, time, etc.

You must first create a Date object using new Date() to use these methods.


🔹 Common Date Get Methods

Method Description Example Output
getFullYear() Returns the 4-digit year 2025
getMonth() Returns month (0–11) → January is 0 6 for July
getDate() Returns day of the month (1–31) 10
getDay() Returns day of week (0–6), where Sunday is 0 4 for Thursday
getHours() Returns hours (0–23) 14 for 2 PM
getMinutes() Returns minutes (0–59) 45
getSeconds() Returns seconds (0–59) 30
getMilliseconds() Returns milliseconds (0–999) 874
getTime() Returns timestamp (milliseconds since Jan 1, 1970) 1752196800000
getUTCFullYear() Returns year in UTC time 2025
getTimezoneOffset() Returns difference in minutes between UTC and local -330 (for IST)

🔹 Example

let d = new Date("2025-07-10T14:45:30");

console.log(d.getFullYear());       // 2025
console.log(d.getMonth());          // 6 (July)
console.log(d.getDate());           // 10
console.log(d.getDay());            // 4 (Thursday)
console.log(d.getHours());          // 14
console.log(d.getMinutes());        // 45
console.log(d.getSeconds());        // 30
console.log(d.getMilliseconds());   // 0
console.log(d.getTime());           // 1752199530000
console.log(d.getTimezoneOffset()); // Example: -330 for IST

Practice Questions

Q1. How do you get the full year (e.g., 2025) from a Date object?

Q2. What will getMonth() return for the month of July?

Q3. How do you extract the day of the month (like 10) from a date?

Q4. Which method gives the day of the week as a number (0 for Sunday)?

Q5. How can you retrieve the hour (24-hour format) from a Date object?

Q6. Which method gives you the number of minutes from the Date object?

Q7. How do you get the current time in milliseconds since Jan 1, 1970?

Q8. What method returns the difference in time between UTC and local time (in minutes)?

Q9. What will getSeconds() return if the time is "2025-07-10T14:45:30"?

Q10. How can you get the UTC full year from a Date object?


JS Date Get Methods Quiz

Q1: What does getFullYear() return?

A. Last two digits of year
B. Month number
C. 4-digit year
D. Date string

Q2: What will new Date("2025-07-10").getMonth() return?

A. 7
B. 6
C. 10
D. July

Q3: Which method returns the weekday number, where Sunday is 0?

A. getWeek()
B. getDate()
C. getDay()
D. getMonth()

Q4: Which method is used to get the number of milliseconds since January 1, 1970?

A. getMillis()
B. getMilliseconds()
C. getTime()
D. getTimestamp()

Q5: What does getHours() return if time is "15:30"?

A. 3
B. 15
C. 30
D. 12

Q6: Which of the following will give you the number of minutes past the hour?

A. getHours()
B. getTime()
C. getMinutes()
D. getSeconds()

Q7: If your local timezone is UTC+5:30, what is the return value of getTimezoneOffset()?

A. 330
B. -330
C. 5.5
D. -5.5

Q8: What does getMilliseconds() return?

A. Milliseconds since midnight
B. Milliseconds since 1970
C. Milliseconds part of the current second
D. Nanoseconds

Q9: Which method returns the UTC year from a Date object?

A. getFullYear()
B. getUTCFullYear()
C. getDateUTC()
D. getUTCYear()

Q10: Which method is NOT a valid Date get method?

A. getSeconds()
B. getDay()
C. getYearFull()
D. getTime()

Go Back Top