npmbot.com
AI

dayjs

v1.11.13MITTree-shakeableTS Ready

Fast 2kB alternative to Moment.js with the same modern API.

97/ 100
Excellent Health
Weekly Downloads
22.5M
Bundle Size (gzip)
2.7 kB(6.9 kB min)
Dependencies
Zero Deps
Last Updated
2024-07-15
SPONSORED CLOUD & DEV TOOLSβ€’Google Ads Partner
NPMBot AI Assessment

The easiest drop-in replacement for Moment.js with 97% smaller footprint.

If you love Moment's chainable API (`dayjs().add(7, 'day').format()`) but hate its bundle size, Day.js is the perfect match. It is completely immutable, only 2.7kB gzipped, and uses an opt-in plugin architecture for advanced features like relativeTime or utc.

Key Advantages
  • β€’Almost 1:1 API compatibility with Moment.js
  • β€’Tiny 2.7 kB gzipped core bundle
  • β€’Immutable: operations return a new object rather than mutating state
  • β€’Plugin system keeps bundle lightweight until features are needed
Gotchas & Limitations
  • β€’Requires manual plugin registration (e.g. dayjs.extend(utc))
  • β€’TypeScript type extensions can sometimes require ambient declaration imports
Recommended For:

Replacing Moment.js with zero refactoring headaches, Everyday date formatting, relative time, and display in web apps

Avoid If:

Complex time-zone math without carefully loading timezone plugins

FEATURED PARTNERβ€’Google Ads Partner
Installation & Quickstart
Package Manager Command
javascript
npm install dayjs
dayjs Usage Example
javascript
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);

console.log(dayjs().fromNow());
Compare dayjs with Alternatives