Get the Current Year, Month, and Day in JavaScript
To read today's year, month, and day, take Temporal.Now.plainDateISO(zone) and read .year, .month (1-based), and .day. Part of UTC vs Local Time.
Why this scenario is tricky
Two legacy traps meet here: getMonth() is 0-based (December is 11), and the bare getters use the host zone, so a server reports the wrong day for part of the world. Temporal's fields are 1-based and you name the zone, so both traps disappear.
Minimal working solution
import { Temporal } from '@js-temporal/polyfill';
const d = Temporal.Now.plainDateISO('America/New_York');
const { year, month, day } = d; // month is 1..12
Full production version
import { Temporal } from '@js-temporal/polyfill';
function todayFields(zone = 'UTC') {
const d = Temporal.Now.plainDateISO(zone);
return { year: d.year, month: d.month, day: d.day, weekday: d.dayOfWeek };
}
Verification snippet
Common pitfalls
Frequently Asked Questions
How do I get the current month number in JavaScript?
Read Temporal.Now.plainDateISO(zone).month, which is 1-based so March is 3. The legacy new Date().getMonth() is 0-based (March is 2), which is the classic source of off-by-one month bugs.
Why does the current day differ between my server and browser?
The bare Date getters use the host zone, and servers usually run in UTC, so late-evening or early-morning users see a different calendar day. Read the fields from Temporal.Now.plainDateISO(userZone) to get their day.