How do you create a Date object representing the current moment?
Short answer
new Date() with no arguments creates a Date object set to the current date and time, based on the system clock, represented internally as milliseconds since the Unix epoch (Jan 1, 1970 UTC).
Advertisement
AModel answer
new Date() with no arguments creates a Date object set to the current date and time, based on the system clock, represented internally as milliseconds since the Unix epoch (Jan 1, 1970 UTC).
const now = new Date();
console.log(now.getTime()); // e.g. 1770512400000Real-world example
Timestamping when a user submits a form, for auditing or sorting purposes.
Likely follow-ups
- How do you create a Date for a specific known date?
Related topics