dayjs
Day.js is a minimalist JavaScript library for parsing, validating, manipulating, and formatting dates, designed as a lightweight alternative to Moment.js with a…
Installation
npm install dayjs
yarn add dayjs
pnpm add dayjs
Import
import dayjs from 'dayjs';
Quick Example
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);
const date = dayjs('2024-01-15');
console.log(date.format('MMMM D, YYYY'));
console.log(date.fromNow());About dayjs
Day.js is a minimalist JavaScript library for parsing, validating, manipulating, and formatting dates, designed as a lightweight alternative to Moment.js with a familiar API. At just 2KB minified and gzipped (compared to Moment.js's 67KB), Day.js provides most of the same functionality with a dramatically smaller footprint. Day.js uses an immutable API where all operations return new Day.js instances rather than modifying the original, preventing accidental mutation bugs. The core library covers parsing from strings, timestamps, and Date objects, formatting with Moment.js-compatible tokens, manipulation (add, subtract, startOf, endOf), comparison (isBefore, isAfter, isSame), and display. Additional functionality is available through plugins including relativeTime for human-readable time differences, utc for UTC mode, timezone for IANA timezone support, weekOfYear, isBetween, minMax, and locale support for internationalization. Day.js is the recommended migration path for projects moving away from Moment.js (which is now in maintenance mode), as its API surface is nearly identical. The plugin architecture keeps the core small while allowing teams to opt into additional features as needed.
Quick Facts
| Package | dayjs |
| Category | Utility |
| Weekly Downloads | 18M+ |
| License | MIT |
| Install | npm install dayjs |
Related Packages
date-fns is a modern JavaScript date utility library that provides comprehensive, consistent, and mo…
Moment.js is a JavaScript date library for parsing, validating, manipulating, and formatting dates t…
Lodash is the most popular JavaScript utility library, providing a comprehensive collection of funct…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.