How do I get the current date in JavaScript?
In JavaScript, you can get the current date using the built-in Date object. Here’s the simplest way:
// Create a new Date object for the current date and time
const now = new Date();
console.log(now); // Outputs something like: 2026-04-03T12:34:56.789Z
Common ways to get formatted parts of the date
const now = new Date();
// Get the full year
const year = now.getFullYear(); // e.g., 2026
// Get month (0 = January, 11 = December)
const month = now.getMonth() + 1; // Add 1 to get 1–12
// Get day of the month
const day = now.getDate(); // 1–31
// Get hours, minutes, seconds
const hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
console.log(`${year}-${month}-${day} ${hours}:${minutes}:${seconds}`);
Shortcut: ISO date string
If you want a standardized string:
const now = new Date();
console.log(now.toISOString()); // e.g., "2026-04-03T12:34:56.789Z"
This works anywhere JavaScript runs, including in the browser on LambdaTest/TestMu AI real devices or emulators.