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
npm
npm install dayjspnpm
pnpm add dayjsyarn
yarn add dayjsMethods
No methods match this filter.
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.
dayjs()→ signature from https://cdn.jsdelivr.net/gh/iamkun/dayjs@dev/types/index.d.ts; official text: “declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, strict?: boolean): dayjs.Dayjs”format→ signature from https://cdn.jsdelivr.net/gh/iamkun/dayjs@dev/types/index.d.ts; official text: “format(template?: string): string”add / subtract→ signature from https://cdn.jsdelivr.net/gh/iamkun/dayjs@dev/types/index.d.ts; official text: “add(value: number, unit?: ManipulateType): Dayjs subtract(value: number, unit?: ManipulateType): Dayjs”diff→ signature from https://cdn.jsdelivr.net/gh/iamkun/dayjs@dev/types/index.d.ts; official text: “diff(date?: ConfigType, unit?: QUnitType | OpUnitType, float?: boolean): number”isBefore / isAfter→ signature from https://cdn.jsdelivr.net/gh/iamkun/dayjs@dev/types/index.d.ts; official text: “isBefore(date?: ConfigType, unit?: OpUnitType): boolean isAfter(date?: ConfigType, unit?: OpUnitType): boolean”
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.