JavaScript Dates
JavaScript Date objects represent a single moment in time in a platform-independent format.
Creating Date Objects
Date objects are created with the new Date() constructor.
There are 4 ways to create a new date object:
javascript
new Date()
new Date(year, month, day, hours, minutes, seconds, milliseconds)
new Date(milliseconds)
new Date(date string)Displaying Dates
By default, JavaScript will use the browser's time zone and display a date as a full text string:
html
const d = new Date();
document.getElementById("demo").innerHTML = d;
// Result: Fri Jul 26 2024 10:30:00 GMT+0500 (Pakistan Standard Time)Test Yourself with an Exercise
Which method creates a new Date object?