Moment.js Alternatives (date-fns)

The page below lists some alternatives to moment.js that look smaller. (JavaScript libraries for working with time.)

Brief Comparison

Name Size original/gzipped Tree-shaking Popularity (stars) Methods richness Pattern Timezone Support Locale
Moment.js 329K/69.6K No 43.4k High OO Good (moment-timezone) 123
Luxon 59.9K/17.2K No 9k High OO Good (Intl) -
date-fns 78.4k/13.4k without tree-shaking Yes 21.3k High Functional Good (date-fns-tz) 64
dayjs 6.5k/2.6k without plugins No 25.8k High OO Not yet 130

I like that the code example for date-fns uses Esperanto. :grin:

import { addYears, formatWithOptions, toUpper } from "date-fns/fp";
import { eo } from "date-fns/locale";

const addFiveYears = addYears(5);

const dateToString = formatWithOptions({ locale: eo }, "D MMMM YYYY");

const dates = [
    new Date(2017, 0, 1),
    new Date(2017, 1, 11),
    new Date(2017, 6, 2),
];

const toUpper = arg => String(arg).toUpperCase();

const formattedDates = dates
    .map(addFiveYears)
    .map(dateToString)
    .map(toUpper);
//=> ['1 JANUARO 2022', '11 FEBRUARO 2022', '2 JULIO 2022']