Dayjs: the lightweight JavaScript date library
Dayjs is a fast, immutable JavaScript library for parsing, validating, manipulating and displaying dates and times. It offers the familiar Moment.js API in a file of about 7 kB (roughly 3 kB gzipped), so pages stay quick while your code stays readable. Add plugins and locales only when a project genuinely needs them.
What is Dayjs?
Dayjs is a minimalist JavaScript library created to handle the everyday work of dates and times: reading them, checking them, changing them and showing them to people. Its API mirrors Moment.js very closely, which means anyone who has written moment().format() can write dayjs().format() on day one, without a learning curve.
The difference lies in the footprint. Moment.js grew into a large, mutable library that is now in maintenance mode, while Dayjs keeps a tiny core and moves optional behaviour into plugins. You load only what you use, and every operation returns a fresh instance rather than altering the original, which removes an entire category of subtle bugs.
That design philosophy makes Dayjs especially attractive for performance-conscious teams. Instead of shipping features nobody uses, you assemble a toolkit that matches your product: UTC handling for an international audience, relative time for a social feed, or custom parsing for imported spreadsheets.
The project is open source under the MIT licence, works in every modern browser as well as Node.js, and ships its own TypeScript definitions. It suits single-page applications, server code, dashboards, booking tools and any interface where dates appear on screen.
Key features of Dayjs
A small set of well-judged design decisions makes Dayjs pleasant to work with in projects of every size.
Tiny footprint
The core file is about 7 kB minified and roughly 3 kB gzipped, so there is less JavaScript to download, parse and execute on slower devices.
Immutable by design
Methods such as add() and startOf() return a new object, leaving the original untouched and your state predictable.
Chainable API
Combine parsing, manipulation and display in one readable line, for example moving to the start of a month and formatting the result.
Internationalisation
With 143 locales, month names, weekdays and relative phrases appear in your audience's language, loaded only when required.
Familiar syntax
The API follows Moment.js patterns closely, so existing knowledge, tutorials and much existing code carry across with minimal effort.
Runs everywhere
Dayjs works in all modern browsers, in Node.js and inside frameworks such as React, Vue, Angular and Svelte, with bundled TypeScript types.
Taken together, these qualities mean Dayjs rarely gets in the way. It handles the routine work of dates quietly and consistently, which leaves developers free to concentrate on the product itself rather than on edge cases around months, weekdays and offsets.
How to install Dayjs
Choose the route that matches your workflow. Each option delivers the same library, so you can switch later without changing your code.
Install from npm, Yarn or pnpm
For bundled projects, add the package with your preferred package manager.
npm install dayjs
# or
yarn add dayjs
pnpm add dayjsImport it in your code
Use an ES module import in modern tooling, or require in CommonJS environments such as older Node.js scripts.
import dayjs from 'dayjs'
// CommonJS
const dayjs = require('dayjs')Or load it from a CDN
For a quick prototype or a static page, a single script tag exposes a global dayjs function.
<script src="https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js"></script>Confirm the setup
Log today's date in a readable pattern. If the formatted string appears in the console, the installation is complete. For deeper detail, read our step-by-step installation guide.
Getting started with Dayjs
Every Dayjs workflow begins by creating an instance. Call dayjs() with no arguments for the current moment, or pass an ISO string, a timestamp or a native Date. From there you can read values, change them and format the result.
- Parse strings, numbers and Date objects into a consistent wrapper.
- Get and set units such as year, month, hour or day of the week.
- Manipulate with
add,subtract,startOfandendOf. - Query with
isBefore,isAfterandisSame. - Display with
format,diffandtoISOString.
import dayjs from 'dayjs'
dayjs('2026-11-15') // parse
dayjs().format('DD MMM YYYY') // display
dayjs().set('month', 3).month() // get & set
dayjs().add(7, 'day') // manipulate
dayjs().isBefore(dayjs('2027-01-01')) // query
// chain several steps together
dayjs().startOf('month').add(1, 'day').format('YYYY-MM-DD')
Dayjs formatting tokens at a glance
The format() method converts an instance into text using tokens. Wrap literal words in square brackets, as in [Today is] dddd, so they are not interpreted. Our formatting guide covers every token in depth.
| Token | Meaning | Example output |
|---|---|---|
YYYY / YY | Four or two digit year | 2026 / 26 |
MMMM / MMM / MM | Month name, short name or number | November / Nov / 11 |
DD / D | Day of the month, padded or not | 05 / 5 |
dddd / ddd | Weekday name or short name | Sunday / Sun |
HH / hh A | 24-hour or 12-hour clock with meridiem | 14 / 02 PM |
mm / ss / SSS | Minutes, seconds, milliseconds | 44 / 09 / 250 |
Z / ZZ | UTC offset with or without colon | +05:00 / +0500 |
Popular Dayjs plugins
The core stays small because extra behaviour lives in 37 official plugins. Load one with dayjs.extend(plugin) and its methods become available on every instance.
UTC
Create and display dates in Coordinated Universal Time rather than local time.
Timezone
Convert between IANA zones such as Asia/Karachi or Europe/London.
RelativeTime
Produce phrases like “in 2 days” or “5 minutes ago” with fromNow().
CustomParseFormat
Parse unusual input such as 15/11/2026 by supplying an explicit pattern.
Duration
Represent spans of time for timers, countdowns and elapsed-time reports.
AdvancedFormat
Adds ordinals, quarters, week numbers and Unix tokens to format().
IsBetween
Check whether a date falls inside a range, with control over inclusive bounds.
LocalizedFormat
Use locale-aware shortcuts such as L and LLL for natural output.
See the full picture in our practical guide to plugins.
Dayjs vs Moment.js and other libraries
Each date library makes different trade-offs. The table below summarises where Dayjs sits among the most common choices for JavaScript projects.
| Criterion | Dayjs | Moment.js | date-fns | Luxon |
|---|---|---|---|---|
| Core size (gzipped) | ~3 kB | ~19 kB | Per function | ~24 kB |
| Immutable values | Yes | No | Yes | Yes |
| Chainable API | Yes | Yes | No | Yes |
| Moment-style syntax | Yes | Yes | No | No |
| Time zone support | Plugin | Add-on package | Add-on package | Built in |
| Project status | Active | Maintenance mode | Active | Active |
For teams starting fresh, the choice often comes down to style. date-fns suits developers who prefer standalone functions, Luxon appeals to projects that need rich time zone handling from the outset, and Dayjs offers the best balance of size, familiarity and a fluent, chainable syntax.
If you already rely on Moment.js, Dayjs is usually the gentlest replacement because most calls translate directly. Our migration guide explains the few differences worth testing.
Where Dayjs fits best
Because it is small and predictable, Dayjs earns its place in a wide range of products.
Booking and scheduling
Calculate availability, block out weekends and display appointment slots in the visitor's own format.
Dashboards and reports
Group records by week or quarter, label chart axes and compare this month against the last.
Feeds and notifications
Show friendly timestamps such as “posted 3 hours ago” that refresh naturally as time passes.
Node.js services
Generate expiry dates, schedule jobs and write consistent ISO strings to databases and logs.
Forms and validation
Check that a date of birth is valid, a deadline lies in the future or a range is in the right order.
Global products
Store moments in UTC and present them in each user's time zone and language without heavy dependencies.
Whatever the use case, the same principle applies: keep dates in an unambiguous form such as an ISO string or a timestamp, and let Dayjs convert them into something readable only at the moment they appear on screen.
Dayjs performance and bundle size
Every kilobyte of JavaScript costs download time, parsing time and memory, and those costs are felt most on mid-range phones and patchy connections. Dayjs keeps its core lean, so it adds very little to your bundle even before tree shaking.
Plugins and locales are separate files, which means a project that never formats Japanese dates or converts time zones never pays for that code. In practice, teams replacing Moment.js often see a noticeable reduction in their main bundle and a measurable improvement in first-load metrics.
Speed of execution matters too. Dayjs wraps the native Date object rather than reinventing it, so common operations such as formatting and adding units remain fast in tight loops and large tables.
Approximate gzipped size
Figures are rounded and vary with build tools and the plugins or locales you include.
Download Dayjs
Get the complete source archive, including the core library, every plugin, all 143 locales, TypeScript definitions and the test suite. It is ideal for offline work, auditing the code or building a custom bundle. For most applications, installing from npm remains the simplest way to receive future updates.
Download Dayjs (.zip)- Latest version1.11.23
- Library file7.2 kB (3 kB gzipped)
- Archive sizeAbout 0.7 MB
- LicenceMIT
- FormatZIP source archive
- PlatformsBrowsers & Node.js
- TypesTypeScript included
Dayjs frequently asked questions
Clear answers to the questions developers ask most often before adopting Dayjs.
Dayjs parses, validates, manipulates and formats dates and times in JavaScript. Typical uses include showing readable timestamps, calculating deadlines, grouping data by period and converting between time zones.
Yes. It is released under the MIT licence, which permits use in personal, open-source and commercial software, provided the licence notice is retained.
The minified core file, dayjs.min.js, is about 7.2 kB, which shrinks to roughly 3 kB when served gzipped. Plugins and locales are separate files that add a little more, and only when you load them. The full source download, with tests and every locale, is around 0.7 MB.
In most projects, yes. The API is largely compatible, so many calls work unchanged. The main differences are immutability and the need to enable certain features through plugins.
Yes, through the UTC and Timezone plugins. Together they let you parse a date in a specific IANA zone, convert it to another and guess the visitor's local zone.
Yes. Every manipulation method returns a new instance and leaves the original unchanged, which keeps application state predictable and simplifies debugging.
Type definitions ship with the package, so no separate types package is needed. Enabling esModuleInterop in your configuration allows the default import style.
Import the locale file, for example dayjs/locale/fr, then call dayjs.locale('fr') to set it globally or .locale('fr') on a single instance.
Yes. Install it from npm and import it with either ES module syntax or require. The same API works on the server and in the browser.
The input could not be parsed. Non-ISO strings usually need the CustomParseFormat plugin and an explicit pattern. Check results with isValid() before displaying them.
Yes. It is framework-agnostic, so you import it into components like any other module. Its immutability fits naturally with state management in modern frameworks.
The latest stable release is 1.11.23. A 2.0 series exists in alpha for testing, but the 1.x line is the one recommended for production work.