-
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 Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
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 Canvas
JS Graphics & Charts
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 Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
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 Canvas
JS Graphics & Charts
JavaScript uses the Date object to work with dates and times. It provides multiple methods to create, retrieve, modify, and format dates.
JavaScript counts time in milliseconds from January 1, 1970 (UTC) — called the Unix Epoch.
new Date(); // Current date and time
new Date("2025-07-10"); // Specific date (YYYY-MM-DD)
new Date(2025, 6, 10); // Year, Month (0-based), Day
new Date(2025, 6, 10, 14, 30); // Y, M, D, H, M
📝 Note: Months are zero-based (January = 0, December = 11)
Method | Description | Example |
---|---|---|
getFullYear() |
Get 4-digit year | date.getFullYear() → 2025 |
getMonth() |
Get month (0-11) | date.getMonth() → 6 (July) |
getDate() |
Get day of the month (1-31) | date.getDate() → 10 |
getDay() |
Get day of week (0-6, Sunday = 0) | date.getDay() → 4 (Thursday) |
getHours() |
Get hour (0–23) | date.getHours() |
getMinutes() |
Get minutes | date.getMinutes() |
getSeconds() |
Get seconds | date.getSeconds() |
getMilliseconds() |
Get milliseconds | date.getMilliseconds() |
toDateString() |
Convert to readable date string | date.toDateString() → "Thu Jul 10 2025" |
toTimeString() |
Time portion of date | date.toTimeString() |
toLocaleDateString() |
Localized date | date.toLocaleDateString() |
toISOString() |
ISO 8601 format | date.toISOString() |
let d = new Date();
d.setFullYear(2030); // Change year
d.setMonth(11); // December
d.setDate(25); // 25th
d.setHours(10, 45); // 10:45 AM
Q1. How do you create a date object for July 10, 2025, using the Date constructor?
Q2. How do you get the current year from a Date object?
Q3. Which method returns the name of the day as a number (0 for Sunday to 6 for Saturday)?
Q4. How do you convert a Date object into a human-readable string like "Thu Jul 10 2025"
?
Q5. What does the getMonth()
method return for the month of December?
Q6. How do you change the year of an existing Date object to 2035?
Q7. Which method gives the time portion (HH:MM:SS) of a Date object?
Q8. How do you get today’s date in a localized format for your system?
Q9. What does new Date().toISOString()
return?
Q10. How can you create a date object that includes time as well: July 10, 2025, 15:30?
Q1: What will new Date().getFullYear() return in the year 2025?
Q2: Which method returns the month of a Date object?
Q3: What is the output of new Date(2025, 6, 10).getMonth()?
Q4: Which of the following creates a date for July 10, 2025, at 3:30 PM?
Q5: Which method would you use to get only the date as a string (e.g., "Thu Jul 10 2025")?
Q6: What is returned by getDay() if the date is a Sunday?
Q7: What is the return type of new Date().toISOString()?
Q8: How can you change the date to 25 using a method?
Q9: What does getHours() return?
Q10: Which method returns localized date like "7/10/2025" (based on your system)?