Skip to content

Timezone Conversion ​

Problem ​

An event has one absolute instant but needs distinct local displays for each user.

Solution ​

Parse the API timestamp as an instant and project it with toZoned().

ts
import { format, parse, toZoned } from '@vielzeug/tempo';

const event = parse('2026-04-15T14:00:00Z', { as: 'instant' });

for (const timeZone of ['America/New_York', 'Europe/Berlin', 'Asia/Tokyo']) {
  const local = toZoned(event, { timeZone });
  console.log(format(local, { locale: 'en-US', pattern: 'long' }));
}

Pitfalls ​

  • toZoned() projects the same instant; it does not add elapsed time.
  • Use shift() when arithmetic must resolve plain or instant inputs in a specific timezone.