Overview
Atemporal provides two powerful formatting approaches:- Token-based formatting - Day.js-compatible format strings like
'YYYY-MM-DD' - Intl.DateTimeFormat - Native localization with full ICU support
Token-Based Formatting
Basic Format Tokens
Use format tokens to create custom date strings:Complete Token Reference
- Date Tokens
- Time Tokens
- Time Zone Tokens
| Token | Output | Description |
|---|---|---|
YYYY | 2024 | 4-digit year |
YY | 24 | 2-digit year |
MMMM | January | Full month name |
MMM | Jan | Abbreviated month name |
MM | 01 | Month, 2-digits (01-12) |
M | 1 | Month (1-12) |
DD | 09 | Day of month, 2-digits (01-31) |
D | 9 | Day of month (1-31) |
dddd | Monday | Full weekday name |
ddd | Mon | Short weekday name |
dd | Mo | Min weekday name |
d | 1 | Day of week (1-7, Monday=1) |
Escaping Text
Use square brackets to include literal text:Common Format Patterns
Locale-Specific Formatting
Using Locales with Tokens
Pass a locale code to format month and weekday names:Setting Default Locale
Set a global default locale:Validating Locales
Intl.DateTimeFormat
Use the nativeIntl.DateTimeFormat API for advanced localization:
Custom Intl Options
The Formatting Engine
Atemporal uses a high-performance formatting engine with several optimizations:Fast-Path Optimization
Common patterns use optimized fast paths:Token Compilation and Caching
Format strings are compiled and cached for reuse:Performance Monitoring
Formatting Configuration
Caching Options
Control formatting cache behavior:Token Pooling
Token pooling reduces memory allocations:Best Practices
Use Fast-Path Patterns
Prefer common patterns like
'YYYY-MM-DD' for best performancePre-warm on Startup
Call
prewarmFormattingSystem() during app initializationReuse Format Strings
Use the same format strings to benefit from caching
Set Default Locale
Set a default locale once rather than passing it to each format call
Recommended Patterns
Real-World Examples
User-Friendly Dates
API Response Formatting
Localized Date Picker
Next Steps
Time Zones
Format dates with time zone information
Immutability
Understand how formatting preserves immutability
API Reference
Explore the complete formatting API