npmdayjsv1.11.20
npmIntermediate

dayjs

2KB immutable date time library alternative to Moment.js with the same modern API

datetimeimmutablemomentformattingdayjstypescriptdate-formattingdatetime
The Problem

JavaScript's built-in Date object is notoriously broken โ€” it's mutable (methods modify the object in place), months are zero-indexed, timezone handling is inconsistent, and there's no formatting built in. Moment.js solved this but grew to 67KB and became mutable. Day.js was created to offer the same ergonomics as moment.js in 2KB.

Mental Model

Day.js objects are immutable โ€” every operation returns a new instance, so you never accidentally mutate a date you're sharing. The API mirrors moment.js intentionally, making migration trivial: dayjs('2024-01-15').add(1, 'month').format('YYYY-MM-DD') reads exactly like human intent.

60-second start

Install dayjs

npm install dayjs
import { } from 'dayjs';

Use it when

Use Day.js when you need date parsing, formatting, arithmetic (add/subtract days/months), or comparisons in browser code where bundle size matters. Its plugin system covers timezones, relative time ('3 hours ago'), duration, and ISO weeks.

Skip it when

For complex timezone-aware calendar applications, consider Temporal (the upcoming TC39 proposal) or date-fns with explicit timezone handling. Day.js's plugin system can grow large if you need many features.

Alternatives
date-fnsFunction-based instead of object-based; better tree-shaking since you import only the functions you use
luxonMore robust timezone support built on the Intl API; larger bundle but better for international apps
TemporalUpcoming TC39 built-in that will make date libraries unnecessary โ€” already available via polyfill

Ready to explore the full API?

See every class, function, and relationship in an interactive graph.