Atemporal provides first-class support for time zones through the IANA Time Zone Database. Every Atemporal instance internally uses Temporal.ZonedDateTime, ensuring accurate time zone conversions that account for daylight saving time and historical changes.
Time zones in Atemporal use IANA identifiers like 'America/New_York' or 'Europe/London', not abbreviations like 'EST' or 'GMT'.
import atemporal from 'atemporal';// Create at current time in Tokyoconst tokyoNow = atemporal(undefined, 'Asia/Tokyo');// Parse date string in New York time zoneconst nyDate = atemporal('2024-11-01T10:00:00', 'America/New_York');console.log(nyDate.format('YYYY-MM-DD HH:mm:ss Z'));// Output: 2024-11-01 10:00:00 -04:00
Set a global default time zone for all new instances:
import atemporal from 'atemporal';// Set default to Parisatemporal.setDefaultTimeZone('Europe/Paris');// New instances use the defaultconst now = atemporal();console.log(now.timeZoneId);// Output: Europe/Paris// Reset to UTCatemporal.setDefaultTimeZone('UTC');
Setting a default time zone affects all instances created afterwards. Use with caution in shared codebases.
'America/New_York' // US Eastern'America/Chicago' // US Central'America/Denver' // US Mountain'America/Los_Angeles' // US Pacific'America/Toronto' // Canada Eastern'America/Mexico_City' // Mexico'America/Sao_Paulo' // Brazil'America/Buenos_Aires' // Argentina
const date = atemporal('2024-11-01T10:00:00', 'America/New_York');// Get the IANA identifierconsole.log(date.timeZoneId);// Output: America/New_York// Also available via timeZoneNameconsole.log(date.timeZoneName);// Output: America/New_York
import atemporal from 'atemporal';// Schedule a meeting at 2 PM New York timeconst meetingNY = atemporal('2024-03-15T14:00:00', 'America/New_York');// Show time for different participantsconst meetingLondon = meetingNY.timeZone('Europe/London');const meetingTokyo = meetingNY.timeZone('Asia/Tokyo');console.log(`New York: ${meetingNY.format('HH:mm')}`);console.log(`London: ${meetingLondon.format('HH:mm')}`);console.log(`Tokyo: ${meetingTokyo.format('HH:mm (Day DD)')}`);// Output:// New York: 14:00// London: 18:00// Tokyo: 03:00 (Day 16)
import atemporal from 'atemporal';// API returns UTC timestampconst utcTimestamp = 1710511200000; // milliseconds since epoch// Display in user's local time zoneconst userTimeZone = 'America/Los_Angeles';const localTime = atemporal(utcTimestamp, userTimeZone);console.log(localTime.format('MMMM D, YYYY [at] h:mm A z'));// Output: March 15, 2024 at 10:00 AM America/Los_Angeles
The underlying Temporal API uses native implementations when available
// Get time zone from existing instance (no conversion)const tz = date.timeZoneId; // Fast// Convert to new zone (creates new instance)const converted = date.timeZone('Asia/Tokyo'); // Still fast