Skip to main content

fromTimeZone

Inverse of toTimeZone. It reads a carrier Date's local fields (getHours(), getDate(), and so on) as wall-clock time in the supplied IANA time zone and returns the real instant they represent. Use it to turn a calendar carrier value back into a true Date before persisting, or as the first step when re-projecting events into a different display zone.

The functionality is available in PRO Edition only

PRO

Signature

function fromTimeZone(date: Date, timeZone: string): Date;
ParameterTypeDescription
dateDateCarrier date whose local fields hold the wall-clock time to interpret.
timeZonestringIANA zone identifier (e.g. "America/New_York") the fields belong to.

Returns a new Date for the corresponding instant. Passing the output of toTimeZone(instant, zone) back through fromTimeZone(..., zone) restores the original instant for ordinary, unambiguous times.

Example

import { toTimeZone, fromTimeZone } from "@svar-ui/react-calendar";

const instant = new Date();
const projected = toTimeZone(instant, "America/New_York");

// after the user edits the projected carrier, recover a true instant
const restored = fromTimeZone(projected, "America/New_York");
  • toTimeZone - counterpart that projects an instant into a zone's wall clock.
  • Time zones - full projection model and re-projection patterns.