What is dayjs?
The dayjs npm package is a minimalist JavaScript library that parses, validates, manipulates, and displays dates and times for modern browsers with a largely Moment.js-compatible API. It is lightweight and offers various functionalities to handle dates and times effectively.
What are dayjs's main functionalities?
Parsing
Parse a date string into a dayjs object.
dayjs('2023-04-01')
Validation
Check if a date is valid.
dayjs('2023-04-01').isValid()
Manipulation
Manipulate the date by adding time to it.
dayjs().add(1, 'year')
Display
Display the date in a specified format.
dayjs().format('YYYY-MM-DD')
Query
Query the date to compare with another date.
dayjs().isBefore(dayjs('2023-12-31'))
Localization
Localize the date to a different language.
dayjs().locale('es').format('dddd, MMMM D YYYY')
Timezone
Handle timezone conversions.
dayjs().tz('America/New_York').format()
Other packages similar to dayjs
moment
Moment.js is a legacy date-time library similar to dayjs with a wide range of functionalities but is larger in size and no longer recommended for new projects.
date-fns
Date-fns is a modern date utility library that provides the most comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
luxon
Luxon is a powerful, modern, and friendly wrapper for JavaScript dates and times. It offers a fluent API and aims to be a successor to Moment.js.
English | 简体中文 | 日本語 | Português Brasileiro | 한국어 | Español (España) | Русский
Fast 2kB alternative to Moment.js with the same modern API
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. If you use Moment.js, you already know how to use Day.js.
dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss');
- 🕒 Familiar Moment.js API & patterns
- 💪 Immutable
- 🔥 Chainable
- 🌐 I18n support
- 📦 2kb mini library
- 👫 All browsers supported
Getting Started
Documentation
You can find for more details, API, and other docs on day.js.org website.
Installation
npm install dayjs --save
📚Installation Guide
API
It's easy to use Day.js APIs to parse, validate, manipulate, and display dates and times.
dayjs('2018-08-08')
dayjs().format('{YYYY} MM-DDTHH:mm:ss SSS [Z] A')
dayjs().set('month', 3).month()
dayjs().add(1, 'year')
dayjs().isBefore(dayjs())
📚API Reference
I18n
Day.js has great support for internationalization.
But none of them will be included in your build unless you use it.
import 'dayjs/locale/es'
dayjs.locale('es')
dayjs('2018-05-05').locale('zh-cn').format()
📚Internationalization
Plugin
A plugin is an independent module that can be added to Day.js to extend functionality or add new features.
import advancedFormat from 'dayjs/plugin/advancedFormat'
dayjs.extend(advancedFormat)
dayjs().format('Q Do k kk X x')
📚Plugin List
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
Contributors
This project exists thanks to all the people who contribute.
Please give us a 💖 star 💖 to support us. Thank you.
And thank you to all our backers! 🙏
License
Day.js is licensed under a MIT License.