
Day.js
A small JavaScript library for working with dates and times, with an API similar to Moment.js.
- Stars
- 48.7k
- Forks
- 3.7k
- Licence
- MIT
- Language
- JavaScript
- Last update
- 2 months ago
- Type
- Library
What it is
Day.js is a small JavaScript library (about 2kB, per the README) that parses, checks, changes, and formats dates and times. Its API is largely compatible with Moment.js, so people familiar with Moment.js can use it with little relearning. Its objects are immutable, so operations return new values instead of changing the original.
- Parse a date string and format it, e.g. dayjs('2018-08-08').format(...)
- Add or subtract time, such as dayjs().add(1, 'year')
- Compare dates with isBefore and related query methods
- Display dates in another language by loading a locale such as 'es' or 'zh-cn'
Great for
- JavaScript developers who used Moment.js and want a smaller library
- Front-end projects where bundle size matters
- Apps that need date formatting and simple date arithmetic
- Projects that need localized date output via locale files
Not ideal for
- Projects that need full timezone handling beyond what the README describes; the README does not detail timezone support, so check the docs first
- Non-JavaScript environments, since the library is written for JavaScript
- Users who need a graphical or no-code tool
How to get it
- 1
Install with a package manager
You'll need: Node.js or a JavaScript bundler/browser environment
Install with npm
npm install dayjs --save - 2
Run it
- Install the package with npm install dayjs --save
- Import it in your code or load it in the browser
- Call dayjs() to get the current date and dayjs('2018-08-08') to parse a date
- Use .format('YYYY-MM-DD') to display it
- 3
Get the most out of it
- Load only the locales you need, e.g. import 'dayjs/locale/es', to keep the build small
- Add plugins such as advancedFormat with dayjs.extend() for extra format tokens
- Use .locale('zh-cn') on a single instance to format in one language without changing the global setting
- Read the API reference and plugin list on day.js.org for the full feature set
Downloads
Strengths
- Small footprint (about 2kB according to the README)
- Familiar API for anyone who has used Moment.js
- Immutable and chainable, which makes code easier to reason about
Trade-offs
- Some functionality is in optional plugins, which must be loaded separately
- Compatibility with Moment.js is described as largely, not complete, so some code may need changes
- Documentation and details live on the external site day.js.org rather than the README
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| dayjs (this) | 48.7k | Library | beginner | 2 months ago | JavaScript developers who used Moment.js and want a smaller library |
| luxon | 16.5k | Library | beginner | 3 months ago | JavaScript developers who need to work with dates and time zones in an app |
| flatpickr | 16.5k | Library | beginner | 2.3 years ago | Web developers who need a date or time input in a JavaScript app |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.