About Lesson
Date and Time Functions in JavaScript:
JavaScript provides built-in methods to handle date and time. The core of this functionality is the Date object, which represents a single moment in time and provides methods for creating, manipulating, and formatting dates and times.
Creating a Date Object:
The Date object can be created in multiple ways:
1. Current Date and Time
JavaScript
const now = new Date();
console.log(now); // Outputs the current date and time
2. Specific Date
JavaScript
const specificDate = new Date("2024-11-25");
console.log(specificDate); // Outputs: Mon Nov 25 2024
3. Using Parameters
JavaScript
const dateWithParams = new Date(2024, 10, 25, 10, 30, 0); // Month is zero-based
console.log(dateWithParams); // Outputs: Mon Nov 25 2024 10:30:00
4. Milliseconds Since Epoch (Jan 1, 1970)
JavaScript
const epochDate = new Date(0);
console.log(epochDate); // Outputs: Thu Jan 01 1970 00:00:00 UTC