Day.js

1.11.20 · active · verified Sat Apr 18

Day.js is a minimalist JavaScript library providing a Moment.js-compatible API for parsing, validating, manipulating, and displaying dates and times. At only 2KB, it offers immutability, chainable methods, and extensive internationalization and plugin support. The current stable version is 1.11.20, and the library is actively maintained with frequent bug fix releases.

Common errors

Warnings

Install

Imports

Quickstart

Initializes a Day.js instance for the current date, then manipulates it by setting the year, adding a day, moving to the start of the month, and finally formats it into a specific string.

import dayjs from 'dayjs';

const formattedDate = dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss');

console.log(formattedDate);
// Example output: '2018-01-02 00:00:00'

view raw JSON →