Temporal Types
Temporal's main idea is that "a date" can mean very different things, and each deserves its own type. A payment's timestamp is an exact moment that happened once, everywhere at the same time. A due date is a square on the calendar with no time of day. Office hours are a wall-clock time that repeats daily. A school year is a month range. Choosing the right type removes whole categories of bugs, because each type only has the information it should have. This lesson tours all eight.
In One Minute
- Exact time:
Instant(a moment, no zone) andZonedDateTime(a moment in a named time zone). - Wall-clock (plain) types, no zone:
PlainDate,PlainTime,PlainDateTime,PlainYearMonth,PlainMonthDay. - Amounts of time:
Duration("2 hours 30 minutes", "1 month"). - Rule of thumb: if it happened at a moment, use
InstantorZonedDateTime; if it is a calendar or clock reading, use aPlaintype. - Create any of them with
Temporal.X.from(...)and print with.toString().
The Eight Types
| Type | Holds | Example string | Use for |
|---|---|---|---|
Instant | An exact moment | 2026-01-05T16:00:00Z | Timestamps, logs, "when was this saved" |
ZonedDateTime | A moment plus a time zone | 2026-01-05T10:00:00-06:00[America/Chicago] | Meetings, deadlines at a place |
PlainDate | Year, month, day | 2026-01-05 | Due dates, birthdays, holidays |
PlainTime | Hour, minute, second... | 09:30:00 | Office hours, alarms |
PlainDateTime | Date and time, no zone | 2026-01-05T09:30:00 | A local event before you know the zone |
PlainYearMonth | Year and month | 2026-09 | Billing months, school years, card expiry |
PlainMonthDay | Month and day | 01-05 | Yearly anniversaries |
Duration | An amount of time | P1M15D, PT2H30M | "30 days", "2 hours 30 minutes" |
Exact Time: Instant
An Instant is a single point on the universal timeline, stored as nanoseconds since the Unix epoch. It has no time zone and no calendar: it's what Date really is underneath.
const paidAt = Temporal.Instant.from("2026-01-05T16:00:00Z");
console.log(paidAt.toString());
console.log(paidAt.epochMilliseconds);
console.log(paidAt.toZonedDateTimeISO("America/Chicago").toString());
const fromDate = Temporal.Instant.fromEpochMilliseconds(new Date("2026-01-05T16:00:00Z").getTime());
console.log(fromDate.equals(paidAt));2026-01-05T16:00:00Z
1767628800000
2026-01-05T10:00:00-06:00[America/Chicago]
trueUse Instant for anything recorded by a machine: when a payment was saved, when a log line was written. To show it to a person, convert it to a ZonedDateTime in their zone. fromEpochMilliseconds converts from a Date timestamp.
Exact Time in a Place: ZonedDateTime
A ZonedDateTime is a moment plus a time zone, so it knows both the exact time and the local clock reading there. It is the only type that handles daylight saving time correctly:
const meeting = Temporal.ZonedDateTime.from("2026-03-07T09:00:00[America/Chicago]");
console.log(meeting.toString());
console.log(meeting.hour, meeting.offset);
const nextDay = meeting.add({ days: 1 });
console.log(nextDay.toString());
console.log(nextDay.hour, nextDay.offset);
console.log(meeting.withTimeZone("America/Los_Angeles").toPlainTime().toString());2026-03-07T09:00:00-06:00[America/Chicago]
9 -06:00
2026-03-08T09:00:00-05:00[America/Chicago]
9 -05:00
07:00:00Explanation: March 8, 2026 is the US daylight saving change. Adding one day keeps the meeting at 9:00 on the wall clock, even though the UTC offset changed from −06:00 to −05:00 (so only 23 real hours passed). withTimeZone shows the same moment in Los Angeles: 7:00 AM.
Plain Types: Calendar and Clock Readings
"Plain" means no time zone: just what a calendar or clock shows. Plain values can't be converted to an exact moment until you supply a zone.
PlainDate
const birthday = Temporal.PlainDate.from({ year: 2014, month: 7, day: 21 });
console.log(birthday.toString(), birthday.dayOfWeek, birthday.dayOfYear);
console.log(birthday.toLocaleString("en-US", { weekday: "long", month: "long", day: "numeric", year: "numeric" }));2014-07-21 1 202
Monday, July 21, 2014A due date, birthday or holiday is a PlainDate: it is "July 21" everywhere, never shifted by a zone.
PlainTime and PlainDateTime
const opens = Temporal.PlainTime.from("08:30");
const closes = Temporal.PlainTime.from("17:00");
console.log(opens.toString(), closes.toString());
console.log(opens.until(closes).toString());
const recital = Temporal.PlainDateTime.from("2026-05-16T18:30");
console.log(recital.toString());
console.log(recital.toZonedDateTime("America/Chicago").toInstant().toString());08:30:00 17:00:00
PT8H30M
2026-05-16T18:30:00
2026-05-16T23:30:00ZA PlainDateTime is a date and time "on the wall" with no zone attached. To know the exact moment, combine it with a zone using toZonedDateTime, then toInstant if you need UTC.
PlainYearMonth and PlainMonthDay
const billing = Temporal.PlainYearMonth.from("2026-02");
console.log(billing.toString(), billing.daysInMonth, billing.add({ months: 1 }).toString());
const anniversary = Temporal.PlainMonthDay.from("02-29");
console.log(anniversary.toString());
console.log(anniversary.toPlainDate({ year: 2027 }).toString());
console.log(anniversary.toPlainDate({ year: 2028 }).toString());2026-02 28 2026-03
02-29
2027-02-28
2028-02-29PlainYearMonth fits billing periods and card expiry dates. PlainMonthDay is a yearly date; February 29 becomes February 28 in years that don't have one.
Duration
A Duration is an amount of time, written in ISO 8601 duration format: P (period), then years, months, weeks, days, then T and hours, minutes, seconds:
const grace = Temporal.Duration.from({ days: 10 });
const lesson = Temporal.Duration.from("PT1H45M");
console.log(grace.toString(), lesson.toString());
console.log(lesson.total({ unit: "minutes" }));
console.log(lesson.add({ minutes: 30 }).toString());
console.log(Temporal.Duration.from({ hours: 26 }).round({ largestUnit: "days", relativeTo: "2026-01-05" }).toString());P10D PT1H45M
105
PT2H15M
P1DT2Htotal converts to one unit. round with largestUnit rebalances; a relativeTo date is needed whenever days or months are involved, because their length varies.
Choosing the Right Type
| Question | Type |
|---|---|
| When did this event happen (for the computer)? | Instant |
| When does this meeting happen, in Dallas? | ZonedDateTime |
| Which day is the fee due? | PlainDate |
| What time does the office open? | PlainTime |
| A local date and time, zone not yet known? | PlainDateTime |
| Which billing month? | PlainYearMonth |
| A yearly date like a birthday? | PlainMonthDay |
| How long? | Duration |
In Practice
The Fee Tracker stores each kind of value in the type that matches its meaning, then combines them to answer "is the office open when this payment arrived?":
const office = { zone: "America/Chicago", opens: Temporal.PlainTime.from("08:30"), closes: Temporal.PlainTime.from("17:00") };
function receivedDuringHours(instantString) {
const local = Temporal.Instant.from(instantString).toZonedDateTimeISO(office.zone);
const time = local.toPlainTime();
const open = Temporal.PlainTime.compare(time, office.opens) >= 0 && Temporal.PlainTime.compare(time, office.closes) < 0;
return `${local.toPlainDate()} ${time.toString({ smallestUnit: "minute" })} local: ${open ? "office open" : "after hours"}`;
}
console.log(receivedDuringHours("2026-01-05T15:10:00Z"));
console.log(receivedDuringHours("2026-01-05T23:45:00Z"));2026-01-05 09:10 local: office open
2026-01-05 17:45 local: after hoursCommon Mistakes
Using ZonedDateTime for a due date. A due date is the same calendar day everywhere: PlainDate.
Using PlainDateTime for an event that happened. Without a zone, it doesn't identify a moment. Use Instant or ZonedDateTime.
Adding days to an Instant. Instant only accepts exact units (hours and smaller), because a "day" depends on the zone. Convert to ZonedDateTime first.
Comparing different types. PlainDate.compare takes two PlainDates; convert values to the same type before comparing.
Practice
Challenge: A video call is at 2026-11-20 at 10:00 in America/Chicago. Print the local time of the call in America/Los_Angeles and in America/New_York, using ZonedDateTime.
Show solution
const call = Temporal.ZonedDateTime.from("2026-11-20T10:00[America/Chicago]");
for (const zone of ["America/Los_Angeles", "America/New_York"]) {
console.log(zone, call.withTimeZone(zone).toPlainTime().toString({ smallestUnit: "minute" }));
}America/Los_Angeles 08:00
America/New_York 11:00Key Takeaways
| Value | Type |
|---|---|
| Payment saved at | Instant |
| Meeting in Dallas | ZonedDateTime |
| Due date | PlainDate |
| Office opens | PlainTime |
| Billing month | PlainYearMonth |
| Grace period | Duration |
Was this tutorial helpful?