Fast 2kB alternative to Moment.js with the same modern API
- 🕒 Familiar Moment.js API & patterns
- 💪 Immutable
- 🔥 Chainable
- 🌐 I18n support
- 📦 2kb mini library
- 👫 All browsers supported
Extensions to the original project
- New plugin "customParseFormat" to parse input strings using custom formats.
- New plugin "localizableFormat" to format dates according to the chosen locale.
- New plugin "timeZone" to parse from and format to a date string using a time zone specified by its canonical name.
- Corrected plugin "relativeTime" honouring grammar rules of the supported languages.
- "UTC mode" for working in UTC, or for working with date-only values without the time part.
- Additional locales (cs, ru, sk, uk).
- Check for
dayjsinstance by the
Day.js is usually imported via a "proxy module", which loads required plugins and registers required language packs. For example, via the following
// Load dayjs, plugins and language packs.// import "timeZone-1900-2050", "timeZone-1970-2038"// or "timeZone-2012-2022" to save your package size// Register plugins and language packs; Czech will be the default language.dayjs
Typical usage scenarios:
// Load a date+time from a storage and show it to the user.const dateTime =console// Prints "28.10.2018 19:45".console// Prints "před 5 hodinami" (5 hours ago).// Read a date+time from the user and format it for the storage.const dateTime =console// Prints "2018-10-28T18:45:00.000Z".// Set only the date; zero the time and prevent local time zone conversion.const dateOnly =console// Prints "2018-10-28" anytime and anywhere.
If used in the browser, the following scripts would be needed:
npm install dayjs-ext --save
It's easy to use Day.js APIs to parse, validate, manipulate, and display dates and times.
// parse// display// get & set// manipulate// query
Day.js has great support for internationalization.
But none of them will be included in your build unless you use it.
dayjs // use Spanish locale globally// use Chinese Simplified locale in a specific instance
A plugin is an independent module that can be added to Day.js to extend functionality or add new features.
dayjs // use plugin// convert to CET before formatting
See the sponsor list at the original project. Thank you for your support!
See the contributor list at the original project. Thank you for your help!
Day.js is Extended licensed under a MIT License.