JavaScript Date
Subject: JavaScript
The JavaScript Date object is used to work with dates and times. It provides methods to create, retrieve, manipulate, and format date and time values. This object is essential for features like clocks, calendars, timestamps, logs, and scheduling.
Creating a Date Object
JavaScript offers multiple ways to create a Date object:
- Current Date and Time
 
- Create a Date from a Date String
 
- Create a Date Using Year, Month, Day, etc.
 
- Create a Date from Milliseconds Since 1970 (Unix Time)
 
Date Methods
Get Date Components
Set Date Components
Format a Date into Readable String
Comparing Dates
Get Timestamp (Milliseconds Since 1970)
Example: Display Current Date in Custom Format
Key Takeaways
- The Date object lets you create, manipulate, and display date/time in JavaScript.
 - Create dates from strings, numbers, or individual components.
 - Use methods like getFullYear(), getMonth(), and getDate() to retrieve values.
 - Use Date.now() or new Date().getTime() for timestamps.
 - Months are zero-based in JavaScript (January is 0).