-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
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 Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Web APIs
Web API Intro
Web Validation API
Web History API
Web Storage API
Web Worker API
Web Fetch API
Web Geolocation API
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Graphics & Charts
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 usingnew Date()
to use these 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) |
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
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 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 Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Web APIs
Web API Intro
Web Validation API
Web History API
Web Storage API
Web Worker API
Web Fetch API
Web Geolocation API
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Graphics & Charts