Skip to main content

dayjs

Library for parsing, validation, and manipulation of Date objects.

Submit feedback
github

Usage

Abyss tools include the Day.js library, which can be used in your own components. Day.js is a minimalist JavaScript library that parses, validates, manipulates, and displays dates and times for modern browsers with a largely Moment.js-compatible API.

Import Day.js

import { dayjs } from '@uhg-abyss/web/tools/dayjs';

Usage examples

Below are some common examples of how to use Day.js:

const currentDate = dayjs();
const dateFromIsoString = dayjs('2018-04-04T16:00:00.000Z');
const dateFromUnix = dayjs(1318781876406);
const dateFromString = dayjs('07/01/2025', 'MM/DD/YYYY');
const dateInCurrentMonth = dayjs().date();
const sevenDaysFromCurrentDate = dayjs().add(7, 'day');
const millisecondsBetweenTwoDates = dayjs('2019-01-25').diff(
dayjs('2018-06-05')
);

Installation recommendation

While Abyss provides Day.js and several common plugins out of the box, we recommend installing Day.js separately in your project if you:

  • Need plugins that aren't included in Abyss
  • Want to control your own Day.js version
  • Have specific date/time manipulation requirements

If you only need the basic plugins we provide, you can continue using the Abyss-provided version.

Abyss default plugins

The following Day.js plugins are available in Abyss:

  • isSameOrBefore
  • isSameOrAfter
  • isYesterday
  • isLeapYear
  • isTomorrow
  • isBetween
  • duration
  • toObject
  • isToday
  • customParseFormat

Example usage:

// Check if a date is between two other dates
dayjs('2019-01-25').isBetween('2019-01-01', '2019-02-01');
// Convert to object
dayjs('2019-01-25').toObject();
// Check if it's today
dayjs().isToday();
// duration
dayjs.duration(100);
// isBetween
dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25'), 'year');
// isTomorrow
dayjs().add(1, 'day').isTomorrow();
// isLeapYear
dayjs('2000-01-01').isLeapYear();
// isYesterday
dayjs().add(-1, 'day').isYesterday();
// isSameOrAfter
dayjs('2010-10-20').isSameOrAfter('2010-10-19', 'year');
// isSameOrBefore
dayjs('2010-10-20').isSameOrBefore('2010-10-19', 'year');
Table of Contents