We use cookies to understand how the site is used and to display ads. Analytics and advertising only run after you accept. You can change your choice anytime. Privacy policy

Skip to content
devvkit
$devvkit learn --librarie day.js-guide

Day.js Guide

[date][time][utilities]
JavaScript / TypeScript
Install
npm install dayjs

Day.js offers Moment.js-compatible API at a fraction of the size (2kB).

Plugin architecture keeps core small: add only what you need.

Immutable: calling .add() returns a new instance, avoiding mutation bugs.

Parsing & Display

Parse· Create from string.
import dayjs from 'dayjs';
dayjs();
dayjs('2026-07-13');
dayjs('2026-07-13', 'YYYY-MM-DD');
Format· Output formatted string.
dayjs().format('YYYY-MM-DD');     // '2026-07-13'
dayjs().format('MMM D, YYYY');     // 'Jul 13, 2026'

Manipulation

Add / subtract· Modify date.
dayjs().add(7, 'day');
dayjs().subtract(1, 'month');
Start of· Start of time unit.
dayjs().startOf('month'); // 2026-07-01 00:00:00
dayjs().endOf('month');

Comparison

Difference· Calculate difference.
dayjs('2026-07-13').diff(dayjs('2026-01-01'), 'day'); // 193

Plugins

Relative time· "3 hours ago".
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);
dayjs('2026-07-10').fromNow(); // '3 days ago'
UTC· UTC mode.
import utc from 'dayjs/plugin/utc';
dayjs.extend(utc);
dayjs.utc().format();
Timezone· Convert timezones.
import timezone from 'dayjs/plugin/timezone';
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.tz('2026-07-13 12:00', 'America/New_York');

Localization

Locale· Display in language.
import 'dayjs/locale/fr';
dayjs.locale('fr');
dayjs('2026-07-13').format('dddd D MMMM');