Working with Dates is a common task while building an application. First, we store the Date object, retrieve & then convert it into readable form, when it comes to a special format traditionally, we need to use a lot of functions and methods that make the process problematic and complex.
Even when I have used to work with dates, converting them into desirable formats becomes problematic. I used to do a lot of research over the StackOverflow; how to change into this, that format blah blah ...
So, through the article, we will see a few JS libraries which will make the building process easy.
1. Day.js - Day.js is a minimalist JavaScript library for working the dates and times.
- Bundle size 2KB which is very less.
- Alternative to moment.js.
- Works both with Node.js and Browser.
- Install using
npm install dayjs
command
2️. date-fns - This is a modern JS library that is simple & a toolset for manipulating dates.
- Simple & 200+ functions.
- Works both with Node.js and Browser.
- Install using
npm install date-fns
command. - date-fns provides some optional features through submodules in the same package.
3. js-joda - js-joda is a lightweight & fast library which has no third party dependencies.
- 43Kb Size and compressed
- Works both with Node.js and Browser.
- Install using
npm install @js-joda/core
command.
4️. Luxon - If we need operations like add, subtract & parse with dates then, Luxon provides an easy way to deal with it.
Good for Math operations.
Works both with Node.js and Browser.
Install using
npm install luxon
command.
Q. Why we haven't discussed yet Moment.js 🤔
You might be thinking why we haven't discussed yet a famous library Moment.js. Moment.js itself says not to use it for your new projects because of its size and immutability of objects & as a result, it increases web application size.
-If you are using Moment in your old project then you should continue with it.
🏁 We have discussed Date-Time libraries that make working with JavaScript dates easy. I have personally used Day.js, so in the next article, we will take a deeper look at Day.js.
-If you have used some other library, please mention it in the comments, It will be great to see you.
Top comments (1)
There is also timewave