JavaScript

coding learning websites codepractice

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?


JavaScript

online coding class codepractice

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

Go Back Top