How to Get Current Date in JavaScript
Use new Date() when your code needs the current date or time for timestamps, greetings, dashboards, logs, or countdown logic. This is the standard way to access the user’s local current date in JavaScript.
What you’ll build or solve
You’ll learn how to get the current date in JavaScript using the Date object. You’ll also know how to extract the day, month, year, and readable formats.
Learn JavaScript on Mimo
When this approach works best
This approach is the right choice when the app needs “right now” based on the user’s device.
Common real-world scenarios include:
- Timestamps
- Greeting by time
- Current day labels
- Form defaults
- Countdown starting points
This is a bad idea when the date must come from a server as the source of truth. In that case, fetch the backend timestamp instead.
Prerequisites
You only need:
- A JavaScript file or browser console
- Basic variables knowledge
Step-by-step instructions
Step 1: Create a new Date object for the current moment
Use new Date() with no arguments.
JavaScript
const now = new Date();
console.log(now);
This gives the current local date and time from the user’s device.
Extract specific parts when needed.
JavaScript
const year = now.getFullYear();
const month = now.getMonth() + 1;
const day = now.getDate();
Use toLocaleDateString() for readable output.
JavaScript
const readableDate = now.toLocaleDateString();
What to look for:
new Date()gives the current local momentgetMonth()starts at0- Add
1to human-readable months - Great for timestamps and UI labels
- Device clock affects the result
Examples you can copy
Current year
JavaScript
const year = new Date().getFullYear();
Today label
JavaScript
const today = new Date().toLocaleDateString();
Greeting hour
JavaScript
const hour = new Date().getHours();
Common mistakes and how to fix them
Mistake 1: Forgetting new
What the reader might do:
JavaScript
const now = Date();
Why it breaks: this returns a string instead of a Date object.
Corrected approach:
JavaScript
const now = new Date();
Mistake 2: Forgetting month zero-indexing
What the reader might do:
JavaScript
const month = now.getMonth();
Why it breaks: January becomes 0.
Corrected approach:
JavaScript
const month = now.getMonth() + 1;
Mistake 3: Using client time when server truth is required
What the reader might do:
JavaScript
const timestamp = new Date();
Why it breaks: device clocks can be wrong.
Corrected approach:
Use a backend-provided timestamp for authoritative dates.
Troubleshooting
If the month looks one behind, add 1.
If the result is a string, confirm new Date() is used.
If timestamps differ across users, decide whether server time is needed.
If formatting looks odd, use toLocaleDateString() with locale options.
Quick recap
- Use
new Date()for the current local moment - Extract parts with getters
- Add
1togetMonth() - Use locale formatting for display
- Use server time when accuracy matters
Join 35M+ people learning for free on Mimo
4.8 out of 5 across 1M+ reviews
Check us out on Apple AppStore, Google Play Store, and Trustpilot