🛠️
Utility18M+/wkMIT

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
npm install dayjs
yarn
yarn add dayjs
pnpm
pnpm add dayjs

Import

ESM
import dayjs from 'dayjs';

Quick Example

usage
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

Packagedayjs
CategoryUtility
Weekly Downloads18M+
LicenseMIT
Installnpm install dayjs

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.