The Date() constructor is used to create Date objects in JavaScript, which represent points in time. Date objects allow you to work with dates and times, including getting the current date and time, manipulating dates, and formatting date and time values.
// Create a new Date object for the current date and time
const now = new Date()
console.log('Current Date and Time:', now)
You can use the Date() constructor to display the current year in a website footer, calculate the difference between two dates, or format dates for display.
// Display the current year in the footer
const currentYear = new Date().getFullYear()
document.getElementById('footer').innerText = `© ${currentYear} My Website
For more advanced date and time manipulation, consider using libraries like Moment.js, luxon, or date-fns.