Overview

Day.js is a JavaScript library that simplifies date and time manipulation, offering a concise and efficient solution for developers. It provides a familiar API, closely mirroring that of Moment.js, which makes it an accessible choice for those transitioning from or seeking an alternative to the larger Moment.js library. Day.js prioritizes performance and a minimal footprint, making it particularly suitable for web applications where bundle size directly impacts load times and user experience. The library is designed to be immutable, meaning that all API operations return a new Day.js object rather than modifying the original, which can contribute to more predictable code and easier debugging.

The library supports various parsing formats, allowing developers to create Day.js objects from strings, numbers, or existing Date objects. Once a Day.js object is created, a wide array of methods become available for formatting dates into custom strings, adding or subtracting units of time (like days, months, or years), and performing complex date calculations. Its extensibility through a plugin system allows developers to add features like timezone support, relative time formatting, or advanced parsing capabilities without increasing the core library's size. This modular approach ensures that applications only include the functionality they require, maintaining its lightweight nature.

Day.js is well-suited for both client-side browser applications and server-side Node.js environments. Its small size, typically around 2KB minified and gzipped, is a significant advantage over Moment.js, which can be considerably larger. This makes Day.js a strong contender for projects where every kilobyte counts, such as mobile-first web applications or single-page applications with strict performance budgets. The library's design emphasizes developer experience, offering clear documentation and a straightforward API that reduces the learning curve for new users while providing powerful features for complex date handling scenarios. For example, when comparing date utility libraries, the date-fns documentation highlights its own modularity benefits, a design principle also central to Day.js for efficient bundle sizes.

Beyond basic formatting and manipulation, Day.js also handles internationalization (i18n) and localization (l10n) through its locale support. Developers can load different locale files to display dates and times according to regional conventions, including month names, day names, and various date formats. This global readiness is crucial for applications serving a diverse user base. The library's API design also facilitates chaining methods, allowing for expressive and readable code when performing multiple date operations sequentially. This fluent interface contributes to the overall developer efficiency and readability of date-related logic within an application.

Key features

  • Immutable Date Objects: All date manipulation methods return a new Day.js object, ensuring that original date objects remain unchanged, promoting predictable state management.
  • Moment.js-Compatible API: Offers an API design that closely matches Moment.js, simplifying the migration process for developers familiar with that library.
  • Tiny Bundle Size: Exceptionally small footprint (around 2KB gzipped) suitable for performance-critical applications and web projects where every byte matters.
  • Extensible Plugin System: Allows developers to add specific functionalities like timezone support, relative time, or advanced parsing without increasing the core library size, maintaining modularity.
  • Internationalization (i18n) Support: Provides comprehensive locale support to format dates and times according to various regional conventions and languages.
  • Flexible Parsing: Capable of parsing dates from various inputs including strings, numbers, JavaScript Date objects, and custom formats.
  • Chaining API: Supports method chaining for sequential date operations, enabling more readable and concise code for complex date logic.
  • Browser and Node.js Compatible: Functions seamlessly in both client-side web browsers and server-side Node.js environments.

Pricing

Day.js is distributed under the MIT License, making it a free and open-source project. There are no licensing fees, subscription costs, or hidden charges associated with its use in personal or commercial projects. The library is maintained by a community of contributors and does not offer commercial support plans or paid tiers.

Feature Day.js
Licensing Model MIT License
Cost Free
Commercial Support Not offered
Updates & Maintenance Community-driven

Pricing information as of June 2026.

Common integrations

Day.js is a standalone utility library, meaning it integrates directly into any JavaScript project without requiring specific frameworks or platforms. Its primary integration method involves importing the library and its optional plugins into a JavaScript or TypeScript codebase. For developers using bundlers like Webpack or Parcel, Day.js can be imported as a module. For example, to use Day.js in a React or Vue application, you would typically install it via npm or yarn and then import it into your components or utility files. This allows it to be used within component logic, Redux reducers, or any other part of the application that requires date manipulation.

  • Web Browsers: Directly import Day.js via a script tag or module bundler for client-side date operations in any browser-based application. The Day.js documentation provides clear guidance on installing Day.js in a project.
  • Node.js Applications: Use Day.js in server-side JavaScript environments, common for API development, data processing, and backend services.
  • Frontend Frameworks (React, Vue, Angular): Integrate Day.js into components for displaying formatted dates, handling form inputs, and managing time-based UI elements.
  • Date Pickers & UI Libraries: Often used as the underlying date manipulation engine for custom date picker components or integrated into existing UI frameworks.
  • Data Visualization Libraries (e.g., Chart.js, Highcharts): Format and process date-time data for charts and graphs, ensuring proper axis labeling and time series representation. For instance, Highcharts datetime axis documentation details how date objects are handled for charting.

Alternatives

  • Moment.js: A comprehensive, widely-used JavaScript date library, often considered a predecessor to Day.js, known for its rich feature set but larger bundle size.
  • date-fns: A modular JavaScript date utility library that provides a collection of functions for date manipulation, emphasizing immutability and tree-shaking support.
  • Luxon: A modern, immutable, and powerful JavaScript library for dates and times, built by the Moment.js team, offering advanced features and timezone handling.

Getting started

To begin using Day.js in a new project, follow these steps. First, ensure you have Node.js and npm (or yarn) installed on your system. You can then install Day.js via your preferred package manager. Once installed, you can import Day.js and start performing date operations immediately. The following example demonstrates how to install Day.js, create a date object, format it, and perform a simple manipulation:

# Install Day.js using npm
npm install dayjs

# Or using yarn
yarn add dayjs

After installation, you can use Day.js in your JavaScript files:

import dayjs from 'dayjs';

// Create a Day.js object for the current date and time
const now = dayjs();
console.log('Current date and time:', now.format());

// Format the date into a more readable string
const formattedDate = now.format('YYYY-MM-DD HH:mm:ss');
console.log('Formatted date:', formattedDate);

// Add 7 days to the current date
const sevenDaysLater = now.add(7, 'day');
console.log('7 days from now:', sevenDaysLater.format('MMMM D, YYYY'));

// Subtract 1 month from the current date
const oneMonthAgo = now.subtract(1, 'month');
console.log('One month ago:', oneMonthAgo.format('YYYY/MM/DD'));

// Check if a date is before another date
const someDate = dayjs('2025-01-15');
const isBefore = now.isBefore(someDate);
console.log(`Is current date before 2025-01-15? ${isBefore}`);

// Use a plugin (e.g., for relative time, requires separate import)
// To use plugins, you'd typically import them and extend Day.js
// import relativeTime from 'dayjs/plugin/relativeTime';
// dayjs.extend(relativeTime);
// console.log('Time from now:', dayjs('2027-01-01').fromNow());

This snippet illustrates creating a Day.js object, applying common formatting, performing arithmetic operations like adding and subtracting time units, and comparing dates. To explore more advanced features, such as internationalization or specific plugins, consult the Day.js API reference documentation.