Fast 2kB alternative to Moment.js with the same modern API
open sourceMITself-hostablefree
Day.js is a minimalist JavaScript library that parses, validates, manipulates and displays dates and times, with an API that is largely compatible with Moment.js and a core of about 2 kB. Its objects are immutable and chainable, locales are loaded one at a time so only the languages you use reach your build, and anything beyond the core (custom parse formats, relative time, durations, ISO weeks, UTC and IANA time zones) comes from one of 35 official plugins added with dayjs.extend. It parses ISO 8601 strings by default; other formats take a format string and the CustomParseFormat plugin. iamkun created it in 2018, and a 2.0 is in alpha.
Problems it solves
- Moment.js adds a big chunk to my JavaScript bundle just to format a few dates
- swap out Moment in a large codebase without rewriting every date call
- format a timestamp as YYYY-MM-DD in the browser with a tiny dependency
- add days or months to a date in JavaScript without changing the original object
- show '3 hours ago' style relative times in a web app
- convert a time into another IANA time zone like Asia/Taipei in the browser
- parse a date string in a custom format like DD/MM/YYYY in JavaScript
- load only the locale I need for formatted dates instead of shipping every language
- check whether a date is today, or falls between two other dates, in JS
- work with ISO week numbers and quarters for a JavaScript reporting dashboard
Features
- Moment.js-style API: parse, format, get and set, add and subtract, startOf and endOf, isBefore and isSame
- immutable, chainable objects
- core of about 2 kB
- ISO 8601 parsing by default; custom formats with the CustomParseFormat plugin
- locales loaded on demand, per instance or globally
- 35 official plugins, including Timezone, UTC, RelativeTime, Duration, Calendar, IsoWeek, QuarterOfYear and AdvancedFormat
- IANA time zone conversion with dayjs.tz, tz.guess and tz.setDefault (Timezone plugin)
- TypeScript declarations in the package
Capabilities
| Has an API | plan not known |
|---|---|
| Takes plugins | plan not known |
Alternatives
The same job
These do what Day.js does.
