DEV Community

Cover image for JS Date-Time libraries you should use instead of traditional methods 😋
Gulshan Aggarwal
Gulshan Aggarwal

Posted on

6 1

JS Date-Time libraries you should use instead of traditional methods 😋

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.

start

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.

AWS Q Developer image

Your AI Code Assistant

Ask anything about your entire project, code and get answers and even architecture diagrams. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Start free in your IDE

Top comments (1)

Collapse
 
anywhichway profile image
Simon Y. Blackwell

There is also timewave

  • 3.75K minimized/gzipped
  • Small enough for every day date/time math. Powerful enough for games and simulations.
  • Timewave provides much of the same functionality as MomentJS and its replacement Luxon in a smaller package.
  • A simple consistent API across Clocks (DateTimes), Durations, and Periods (Intervals)
  • Concise math operations and duration expressions
  • Multiple time-zone handling
  • Clocks that can be stopped, started, run forward or backward and cloned into different timezones
  • Periods (from time x to time y) that can be adjusted and shifted in pure or mutating mode
  • Alarms that can be invoked when a clock hits a specific time or is within a range

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay