Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Reading UTC Timestamps With Instant

The booking export identifies when Dana’s call happens with a UTC timestamp. UTC means Coordinated Universal Time; the string’s final Z marks that reference. Dana’s named time zone supplies the local clock reading.

Python reads the timestamp with datetime.fromisoformat() and converts it with .astimezone(ZoneInfo(...)). In JavaScript, read the timestamp as a Temporal.Instant first, then call .toZonedDateTimeISO() with the patient’s zone. ISO names the calendar used here; it stands for International Organization for Standardization.

Temporal.ZonedDateTime.from() requires a bracketed time zone annotation when it parses a string. The export’s Z alone does not supply a region’s rules, so the direct port raises a RangeError. A numeric offset also does not name a region.

This fragment belongs in reminders.js in your existing ~/reminders project. That folder’s package.json contains { "type": "module" }. The shown appointment is the export’s first record:

Language: JavaScript
const appt = {
  patient: "Dana Whitfield",
  clinician: "Callum Reid",
  start: "2026-11-01T15:00:00Z",
  minutes: 50,
};
const ZONES = {
  "Dana Whitfield": "America/New_York",
};

const instant = Temporal.Instant.from(appt.start);
const start = instant.toZonedDateTimeISO(
  ZONES[appt.patient],
);
console.log(`${instant}`);
console.log(`${start}`);

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 The closed day needed a calendar date. Dana’s video call needs a moment that both patient and clinician can join. In this lesson, you’ll read the export’s timestamps and show them in the patient’s time zone.

00:12 Dana’s Sunday timestamp ends in Z, meaning Coordinated Universal Time, or UTC. In Python, you read that timestamp, then use Dana’s named zone with astimezone().

00:25 Python prints fifteen hundred in UTC, and ten in New York. An aware Python datetime suggests a ZonedDateTime. The previous type choice still fits the appointment you want to end up with.

00:40 So in JavaScript, you try its from() on the same export string. console.log() would print the result as text.

00:51 What happens when this attempt runs? Your turn: pause the video and predict the result.

01:02 A RangeError stops the file before it prints an appointment. The message says a time zone annotation is required. The export tells you when the call happens.

01:16 Z fixes its position on the UTC timeline. It doesn’t name Dana’s region. A numeric offset also gives a distance from UTC, without naming the region’s clock rules.

01:28 A ZonedDateTime string carries that extra information in brackets. This complete form names New York as well as the clock reading and offset. The closure’s PlainDate has neither a time nor a zone; the export instead identifies an exact moment.

01:46 You need a type for that information first.

01:50 Read the timestamp with Instant first.

01:56 In JavaScript, this value knows the exact moment, without choosing a local clock. It prints the original Z form. Then combine that instant with Dana’s zone using toZonedDateTimeISO().

02:11 The suffix selects the ISO calendar, named for the International Organization for Standardization. Now the result is a ZonedDateTime: ten in New York, with the offset and bracketed zone.

02:25 Python reads and converts with its datetime type. JavaScript makes those two steps explicit with two Temporal types.

02:34 The clinic also needs its own clock reading. In Python, another astimezone() gives the clinic’s London time. In JavaScript, start already has a zone, so use withTimeZone() with Europe slash London.

02:52 The clinic sees fifteen hundred, while Dana sees ten in New York. The point on the timeline stays fixed. These are two clock readings for the same call. Keep the named zones in the clinic’s data, so the conversion has the right regional rules.

03:10 A ZonedDateTime’s toString() includes the bracketed zone, which a booking system may not accept; toInstant().toString() gives back the Z form.

03:20 The call hasn’t moved. You’re choosing the representation the receiver expects.

03:28 Keep the closure’s calendar date separate. An Instant input needs an offset or Z to pin down its moment. A clock reading without either doesn’t identify that moment.

03:38 For this export, read the Z timestamp, keep the patient’s zone alongside it, and convert at the edge where someone needs their local clock. At an edge that still uses Date, Date’s toTemporalInstant() gives an Instant, and new Date() with the zoned value’s epoch milliseconds gives a Date again.

04:02 Its ISO string has the same UTC time, with three millisecond digits. Date keeps millisecond precision, so finer Temporal precision can’t survive that conversion.

04:14 Your rule is timestamp first, named zone second. Use an Instant for the export’s moment, and a ZonedDateTime for someone’s clock. Next up is Comparing and Sorting Appointments.

04:26 You’ll put the clinic’s week in order.

Become a Member to join the conversation.