Temporal Types

Updated · 7 min read
mediumES2026javascripttemporaldatestime-zones

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) and ZonedDateTime (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 Instant or ZonedDateTime; if it is a calendar or clock reading, use a Plain type.
  • Create any of them with Temporal.X.from(...) and print with .toString().

The Eight Types

TypeHoldsExample stringUse for
InstantAn exact moment2026-01-05T16:00:00ZTimestamps, logs, "when was this saved"
ZonedDateTimeA moment plus a time zone2026-01-05T10:00:00-06:00[America/Chicago]Meetings, deadlines at a place
PlainDateYear, month, day2026-01-05Due dates, birthdays, holidays
PlainTimeHour, minute, second...09:30:00Office hours, alarms
PlainDateTimeDate and time, no zone2026-01-05T09:30:00A local event before you know the zone
PlainYearMonthYear and month2026-09Billing months, school years, card expiry
PlainMonthDayMonth and day01-05Yearly anniversaries
DurationAn amount of timeP1M15D, 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.

instant.js▶ Try it
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));
Output
2026-01-05T16:00:00Z
1767628800000
2026-01-05T10:00:00-06:00[America/Chicago]
true

Use 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:

zoned.js▶ Try it
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());
Output
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:00

Explanation: 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

plain-date.js▶ Try it
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" }));
Output
2014-07-21 1 202
Monday, July 21, 2014

A due date, birthday or holiday is a PlainDate: it is "July 21" everywhere, never shifted by a zone.

PlainTime and PlainDateTime

plain-time.js▶ Try it
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());
Output
08:30:00 17:00:00
PT8H30M
2026-05-16T18:30:00
2026-05-16T23:30:00Z

A 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

year-month.js▶ Try it
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());
Output
2026-02 28 2026-03
02-29
2027-02-28
2028-02-29

PlainYearMonth 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:

duration.js▶ Try it
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());
Output
P10D PT1H45M
105
PT2H15M
P1DT2H

total 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

QuestionType
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?":

types.js▶ Try it
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"));
Output
2026-01-05 09:10 local: office open
2026-01-05 17:45 local: after hours

Common 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
call.js▶ Try it
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" }));
}
Output
America/Los_Angeles 08:00
America/New_York 11:00

Quick check: Temporal types

3 questions
1Which type fits a fee's due date?
2Which type handles daylight saving changes correctly when adding days?
3What does "PT1H45M" represent?

Key Takeaways

ValueType
Payment saved atInstant
Meeting in DallasZonedDateTime
Due datePlainDate
Office opensPlainTime
Billing monthPlainYearMonth
Grace periodDuration

Was this tutorial helpful?

Lesson 58 of 139