Formatting Dates for Display
Display dates in different formats
Display dates in different formats
Format dates for user interfaces, reports, or data exports:
Use Intl.DateTimeFormat options for localized formatting that automatically adapts to different languages and regions.
Format with ordinals and advanced tokens
Format with ordinals and advanced tokens
The Available advanced tokens:
advancedFormat plugin adds support for ordinals and other advanced formatting tokens:Do- Day of month with ordinal (1st, 2nd, 3rd, etc.)Qo- Quarter with ordinal (1st, 2nd, 3rd, 4th)zzz- Short timezone name (e.g., “PST”)zzzz- Long timezone name (e.g., “Pacific Standard Time”)
Calculating Time Differences
Calculate duration between dates
Calculate duration between dates
Find the difference between two dates in any time unit:
Humanize durations
Humanize durations
Convert durations into human-readable strings:
Working with Time Zones
Schedule meetings across time zones
Schedule meetings across time zones
Convert times between different time zones for global scheduling:
Always store dates in UTC and convert to local time zones only for display. This prevents ambiguity around daylight saving time transitions.
Set default time zone for your app
Set default time zone for your app
Configure a default time zone for all date operations:
Relative Time Display
Show 'time ago' labels
Show 'time ago' labels
Display human-friendly relative times like “2 hours ago” or “in 3 days”:
Auto-updating timestamps
Auto-updating timestamps
Create live-updating relative timestamps for social media or chat apps:
Business Day Calculations
Calculate business days
Calculate business days
Work with business days, excluding weekends and holidays:
Custom weekend configuration
Custom weekend configuration
Configure custom weekend days for different regions:
Date Range Operations
Generate date ranges
Generate date ranges
Create arrays of dates between two points:
Weekly and monthly ranges
Weekly and monthly ranges
Generate ranges with different intervals:
Schedule and Calendar Operations
Check date range overlaps
Check date range overlaps
Detect if two date ranges overlap:
Check if date is between two dates
Check if date is between two dates
Use comparison methods for scheduling logic:
Parsing Custom Date Formats
Parse dates from strings
Parse dates from strings
Parse dates that don’t follow ISO 8601 format:Supported format tokens:
YYYY- 4-digit yearYY- 2-digit yearMM- Month (01-12)M- Month (1-12)DD- Day (01-31)D- Day (1-31)HH- Hour 24h (00-23)H- Hour 24h (0-23)hh- Hour 12h (01-12)h- Hour 12h (1-12)mm- Minutes (00-59)m- Minutes (0-59)ss- Seconds (00-59)s- Seconds (0-59)A- AM/PMa- am/pm
Parse dates with month names
Parse dates with month names
Handle dates with full or abbreviated month names:
Additional Examples
Find min/max dates
Find min/max dates
Find the earliest or latest date from a list:
Start and end of time periods
Start and end of time periods
Get the beginning or end of various time periods:
Best Practices
Performance Tips:
- Atemporal uses intelligent caching for formatting, parsing, and comparisons
- Reuse atemporal instances when possible - they’re immutable
- Configure default locale and timezone once at app initialization
- Use lazy loading for plugins you don’t need immediately
Type Safety:
- Atemporal is built with TypeScript and provides full type definitions
- All methods return typed results for better IDE support
- Use
.isValid()to check if a date was parsed successfully
Time Zone Safety:
- Always store dates in UTC in your database
- Convert to local time zones only for display
- Use IANA time zone identifiers (e.g., ‘America/New_York’)
- Atemporal handles DST transitions automatically