Skip to content
Home / Migrations / Moment.jsDay.js

Moment.js Day.js

easy

Day.js is a 2KB drop-in replacement for Moment.js (which is deprecated and 70KB). Same API.

Estimated: 1-2h · 5 steps
Progress0%
Step 1: Install Day.js
npm install dayjs && npm uninstall moment
Step 2: Replace imports

Change import moment from 'moment' to import dayjs from 'dayjs'.

find src -name '*.ts*' -exec sed -i "s/import moment from 'moment'/import dayjs from 'dayjs'/g" {} +
Step 3: Replace moment() calls

moment() → dayjs(). Most format/parse/diff methods are identical.

find src -name '*.ts*' -exec sed -i 's/moment(/dayjs(/g' {} +
Step 4: Add plugins for advanced features

Moment features like duration, timezone, relative time require Day.js plugins.

import relativeTime from 'dayjs/plugin/relativeTime'
dayjs.extend(relativeTime)
Step 5: Verify
All date formatting and parsing works correctly