Introduction
Luxon is a modern date-time library for JavaScript that wraps the native Intl API to provide an immutable, chainable interface for parsing, formatting, and manipulating dates across time zones. Built by a core Moment.js maintainer, it addresses Moment's shortcomings — mutability, large bundle size, and limited Intl support.
What Luxon Does
- Represents dates, times, durations, and intervals as immutable objects with a fluent API
- Leverages the native Intl API for locale-aware formatting without shipping locale data
- Handles time zone conversions using IANA zone identifiers without external databases
- Parses ISO 8601, RFC 2822, HTTP dates, and custom format strings
- Performs calendar math including DST-safe addition and difference calculations
Architecture Overview
Luxon centers on the DateTime class, which wraps a timestamp and a zone. All operations return new instances rather than mutating state. The library delegates locale formatting and calendar calculations to the runtime Intl.DateTimeFormat and Intl.RelativeTimeFormat APIs, keeping its own code lean. Duration and Interval classes compose naturally with DateTime for range operations.
Self-Hosting & Configuration
- Install from npm — zero native dependencies, pure JavaScript
- Import named exports: DateTime, Duration, Interval, Settings, Info
- Configure default locale and zone globally via
Settings.defaultLocaleandSettings.defaultZone - Tree-shakeable: unused classes do not inflate your bundle
- Works in Node.js 12+, all modern browsers, Deno, and Bun
Key Features
- Immutable by design — no accidental date mutations in complex pipelines
- First-class time zone support via IANA identifiers and fixed UTC offsets
- Human-friendly duration formatting:
Duration.fromMillis(90000).toFormat('m:ss')yields "1:30" - Relative time output:
dt.toRelative()returns strings like "in 2 hours" using Intl - Over 16,000 GitHub stars with widespread adoption as the Moment.js migration path
Comparison with Similar Tools
- Day.js — smaller bundle with plugin system; Luxon has richer time zone and Intl support built-in
- Moment.js — mutable and deprecated; Luxon is its official successor with immutable design
- date-fns — functional tree-shakeable helpers; Luxon offers an object-oriented chainable API
- Temporal (TC39) — upcoming native API; Luxon works today and shares similar design principles
- js-joda — port of Java's java.time; Luxon leverages native Intl rather than bundling calendars
FAQ
Q: Should I migrate from Moment.js to Luxon? A: Yes. The Moment team recommends Luxon as a modern replacement. It shares similar concepts but fixes mutability and bundle-size issues.
Q: Does Luxon support non-Gregorian calendars? A: It delegates to Intl, so output formatting respects locale calendars. Internal math is Gregorian-based.
Q: How big is Luxon compared to Day.js? A: Luxon is roughly 20 KB minified+gzipped versus Day.js at 2 KB core, but Luxon includes time zone and Intl support that Day.js requires plugins for.
Q: Can I use Luxon in serverless functions? A: Yes. It has no native dependencies and initializes instantly, making it suitable for cold-start-sensitive environments.