About Lesson
Common Date Methods:
1. Getting Components of a Date:
JavaScript
const now = new Date();
console.log(now.getFullYear()); // Year (e.g., 2024)
console.log(now.getMonth()); // Month (0-11, January is 0)
console.log(now.getDate()); // Day of the month (1-31)
console.log(now.getDay()); // Day of the week (0-6, Sunday is 0)
console.log(now.getHours()); // Hours (0-23)
console.log(now.getMinutes()); // Minutes (0-59)
console.log(now.getSeconds()); // Seconds (0-59)
console.log(now.getMilliseconds()); // Milliseconds (0-999)
2. Setting Components of a Date:
JavaScript
const date = new Date();
date.setFullYear(2025);
date.setMonth(5); // June (0-based index)
date.setDate(15);
console.log(date); // Updated date
3. Timestamps:
JavaScript
console.log(Date.now()); // Current timestamp in milliseconds