Skip to content

In JavaScript's Temporal API, when is a ZonedDateTime more useful than a plain Instant?

Show answer & explanation

Answer: When you need both the exact moment and what the local clock says in a particular time zone

When you want to store a calendar date with no time of day at all — Wrong. A calendar date with no time of day is what PlainDate is for. ZonedDateTime carries far more than that, an exact moment plus its zone, which is more than a birthday or a holiday needs.

When you only need to measure how long an operation took — Wrong. Measuring how long something took only needs two Instants and the difference between them; no time zone is involved, so ZonedDateTime adds nothing here. Temporal even has a Duration type for the result.

When you need both the exact moment and what the local clock says in a particular time zone ✓ — Correct! An Instant is a point on the global timeline with no idea of where you are; a ZonedDateTime pairs that moment with a time zone, so it also knows the local wall-clock time, the date and the daylight-saving rules that apply. Meetings, flights and local events need both halves, and that is exactly what ZonedDateTime carries.

Play today's quiz — new questions daily

More Technology questions