Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
The Date object represents a single moment in time. Create dates, get/set components, calculate differences, and format for display.
A specific point in time - like "December 14, 2024 at 3:30 PM"
As milliseconds since January 1, 1970 (Unix epoch)
Create, read, modify, compare, and calculate with dates
new Date()Creates date with current time
new Date('2024-12-14')Creates date from string
new Date(2024, 11, 14)Creates date from year, month, day (month is 0-indexed!)
JavaScript counts months starting from 0:
0= January11= DecemberSo December 14 is written as new Date(2024, 11, 14) not new Date(2024, 12, 14)
Different ways to create Date objects
Extract parts of a date
Modify parts of a date
Add/subtract days, compare dates
Work with Unix timestamps
Practical date operations
January = 0, February = 1, ..., December = 11. Always add 1 when displaying month numbers.
Date object uses local time zone. Use UTC methods (getUTCHours()) for consistent results.
Use ISO 8601 format (YYYY-MM-DD) for reliable cross-browser parsing.
new Date() for current, pass string/timestamp
0-indexed! January=0, December=11
Date.now() or .getTime() for milliseconds
Subtract dates for difference, use setters to add/subtract