Javascript Temporal API

Using Temporal.Now

Igor Komolov
1 min readNov 25, 2023

This object offers several factory methods to create Temporal values for the current time.

Getting the current instant in UTC

Temporal.Now.instant().toString()

Getting the current zoned date-time in a specific timezone

Temporal.Now.zonedDateTimeISO('Asia/Shanghai').toString()

Getting the current plain date-time in ISO format

Temporal.Now.plainDateTimeISO().toString()

Getting the current plain time in ISO format

Temporal.Now.plainTimeISO().toString()​​.

Properties of ZonedDateTime.prototype

The ZonedDateTime class in Temporal has several properties and methods that allow detailed manipulation and retrieval of date-time information.

  • These include getters for calendar, timezone, year, month, day, hour, minute, second, and even nanoseconds.
  • It also includes methods like .with(), .add(), .subtract(), .until(), .since(), and .round(), providing extensive functionality for working with zoned date-time values​​.

Plain Time Classes in Temporal

Temporal introduces “plain” classes, which are abstract representations of time without a time zone.

  • These classes include PlainDateTime, PlainDate, and PlainTime.
  • They are useful for displaying wall-clock time in a given time zone or for time computations where the time zone is irrelevant, like finding the first Tuesday of June 1984.

--

--

Igor Komolov

Founder & CTO who writes code, day trades, cycles, golfs, takes pictures, makes art and reads ALOT.