Temporal
Temporal is the modern replacement for the problematic JavaScript Date object.
JavaScript’s Date object has been a source of frustration for decades. It’s mutable, doesn’t support non-Gregorian calendars well, and handling time zones is notoriously difficult.
The Temporal API is the modern solution, now stable in Deno since v2.7.
Why Temporal?
As Mat Marquis explains in his post, Date is essentially “broken” for modern web development:
- Mutability: Calling a method like
setHours()on aDateobject changes the original object, leading to subtle bugs. - Parsing:
Date.parse()is notoriously inconsistent across different browsers. - Time Zones:
Dateonly supports the user’s local time and UTC.
Temporal solves these problems by being immutable and providing specialized types for different use cases.
Getting Started
In Deno, Temporal is available globally. You don’t need to import anything.
Current Date and Time
The Temporal.Now object provides methods to get the current time in various formats:
// Current date (e.g., 2026-04-07)
;
// Current date and time (e.g., 2026-04-07T12:14:30)
;
// Exact point in time (UTC)
;Core Types
Temporal introduces several types to represent time more accurately:
PlainDate
Represents a date with no time or time zone (e.g., a birthday or a calendar event).
;
birthday.year; // 1995PlainTime
Represents a time of day with no date or time zone (e.g., “the store opens at 9:00”).
;ZonedDateTime
A complete date and time in a specific time zone. This is what you should use for most “real-world” events.
"2026-03-15T14:30[America/New_York]"
);
// Convert to another time zone easily
;Estás leyendo una vista previa.
Inicia sesión para leer el artículo completo. Cualquier cuenta abre 4 artículos gratuitos al mes; el alumnado y el profesorado leen las páginas de su curso sin límite.
Iniciar sesión