PACKAGE · DATE & TIME

dayjs

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

WEEKLY DOWNLOADS 71.3M
STARS 48.7K
FORKS 3.8K
OPEN ISSUES 1.4K
GZIP SIZE 3.4 kB
UNPACKED SIZE 681.7 kB
DEPENDENCIES 1
LAST UPDATED 11mo ago
DOWNLOAD TRENDS

dayjs downloads · last 12 months

Download trends for dayjs1 download series from Oct 2025 to Sep 2026. Use left and right arrow keys to inspect monthly values.073.6M147.2M220.8M294.4MOct 2025JanAprJulSep 2026
dayjs
ABOUT DAYJS

Day.js is a lightweight, immutable date and time library designed as a modern alternative to Moment.js. It addresses the common need for developers to manipulate, format, and parse dates and times in a predictable and efficient manner, offering a familiar API for those migrating from or comparing with Moment.js. Its small footprint makes it an attractive choice for projects where bundle size is a concern.

Developed with a focus on simplicity and immutability, Day.js aims to provide a developer-friendly experience for date operations without the larger overhead of some other libraries. The library is primarily targeted at frontend and backend JavaScript developers who require robust date handling capabilities within their applications, whether for displaying user-friendly timestamps or performing complex chronological calculations.

The core of Day.js's API revolves around a chainable, fluent interface. Developers can instantiate a Day.js object with various inputs (strings, dates, numbers) and then chain methods like `.format()`, `.add()`, `.subtract()`, `.diff()`, and `.startOf()` to perform operations. Its immutable nature ensures that original date objects are never modified, promoting safer state management in applications.

Day.js integrates seamlessly into various JavaScript ecosystems. It is commonly used with popular frontend frameworks like React, Vue, and Angular, as well as in Node.js environments. Its minimal size and straightforward API make it easy to adopt in build processes that leverage tools like Webpack, Rollup, or Vite, and it can be imported using standard ES module syntax.

With a remarkably small bundle size of just 3.4 kB (gzipped), Day.js offers significant performance advantages in terms of load times, especially in client-side applications. This efficiency is achieved through a modular design, allowing developers to import only the functionality they need via plugins, further reducing the final bundle. The library is mature, with extensive community adoption reflected in its 45.2 million weekly downloads and 48.7K GitHub stars.

While Day.js provides a comprehensive set of date manipulation features, developers should be aware that certain advanced functionalities present in larger libraries, such as complex time zone conversions or extensive locale data, might require additional plugins. For extremely niche or highly complex date calculation requirements, careful consideration of plugin availability and the library's core capabilities is advised.

WHEN TO USE
  • When you need to format dates for display in user interfaces, using methods like `dayjs(date).format('YYYY-MM-DD HH:mm:ss')`.
  • When performing relative time calculations, such as determining "a few minutes ago" with `dayjs().fromNow()`.
  • When manipulating dates by adding or subtracting units, for example, `dayjs().add(7, 'day').toDate()`.
  • When comparing dates to find differences in specific units using `dayjs(date1).diff(date2, 'month')`.
  • When dealing with immutable date objects to prevent unintended side effects in state management.
  • When migrating from Moment.js and seeking a compatible API with a significantly smaller bundle size.
  • When building applications that require basic locale support, which can be extended via plugins.
WHEN NOT TO USE
  • If your application requires extensive, built-in internationalization (i18n) for numerous languages and complex locale rules, consider a library with more comprehensive locale data out-of-the-box.
  • If you need highly specialized calendar systems or advanced astronomical calculations, a more domain-specific library might be necessary.
  • When dealing with extremely precise, sub-millisecond time tracking or high-frequency event logging, where a dedicated high-precision timer might be more suitable.
  • If your project's date handling needs are limited to simple date comparisons or retrieval of the current date, native JavaScript `Date` objects might suffice without external dependencies.
  • If strict adherence to complex IETF standards for date parsing with edge cases not covered by the library's parsing capabilities is a primary requirement, manual parsing might be considered.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

COMPARISONS 5
dayjs vs luxon ★ 16.5K · 40.3M/wk dayjs vs @js-joda/core ★ 1.7K · 4.6M/wk dayjs vs @formkit/tempo ★ 2.6K · 94.1K/wk dayjs vs date-fns ★ 36.6K · 98.8M/wk dayjs vs moment ★ 47.9K · 35.0M/wk