API Reference

Day.js

Fast 2KB immutable date library for JavaScript with a Moment.js-compatible API and chainable parsing.

Official Documentation ↗
CompatibilityThis documentation covers version v1.11. Check the official docs for the latest API surface.

Installation

npmnpm install dayjs
pnpmpnpm add dayjs
yarnyarn add dayjs

Methods

Day.js is a minimalist JavaScript date library that parses, validates, manipulates, and displays dates and times. It offers a Moment.js-compatible API in a 2KB immutable package with a plugin system.

Key Features

  • Tiny: 2KB gzipped core with tree-shakeable plugins
  • Immutable: All mutations return new instances
  • Moment-compatible: Familiar API eases migration
  • Plugins: Relative time, UTC, timezone, durations, calendars
  • i18n: Locale loading on demand via dayjs.locale()

API reference evidence

Fetched from official sources on 2026-11-08T19:28:00+08:00 via WebFetch https://cdn.jsdelivr.net/npm/dayjs@latest/types/index.d.ts(404:包内无该路径);WebFetch https://cdn.jsdelivr.net/gh/iamkun/dayjs@dev/types/index.d.ts.

FAQ

How does Day.js compare to Moment.js?
Day.js is immutable, 2KB versus Moment's 67KB, and has a near-identical API. It uses plugins for advanced features, keeping the core tiny. Moment.js is now in maintenance mode.
How do I use plugins in Day.js?
Call dayjs.extend(plugin) before use. For example, import relativeTime from 'dayjs/plugin/relativeTime' then dayjs.extend(relativeTime) to enable .fromNow().
Is Day.js immutable?
Yes. Methods like add, subtract, and set return new Dayjs objects and never mutate the original. This avoids shared-state bugs and works well with React and Redux.