About Lesson
Formatting Dates:
1. Using toLocaleDateString()
JavaScript
const now = new Date();
console.log(now.toLocaleDateString("en-US")); // e.g., "11/25/2024"
console.log(now.toLocaleDateString("en-GB")); // e.g., "25/11/2024"
2. Using toISOString()
JavaScript
console.log(new Date().toISOString()); // e.g., "2024-11-25T10:00:00.000Z"
3. Custom Formatting()
JavaScript
const now = new Date();
console.log(`${now.getDate()}/${now.getMonth() + 1}/${now.getFullYear()}`);
// e.g., "25/11/2024"