dayjs
2KB immutable date time library alternative to Moment.js with the same modern API
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.
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.
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.
Ready to explore the full API?
See every class, function, and relationship in an interactive graph.