DayJS a new alternative to MomentJS

Whenever it’s comes to manipulating dates and showing custom format of dates MomentJS is always the first choice for most of the developer. Recently a new library named DayJS came which excellent features and performance. In this article we will gonna compare MomentJS with DayJS.

What is DayJS ?

Like MomentJS, DayJS is also a date manipulation library. 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.

Comparison

Let’s try to do comparison of both library based on performance, size, browser support, usage etc.

Size

DayJS a new alternative to MomentJS

Currently if we check the size of MomentJS it is 70.4KB on the other hand DayJS size is only 2.8KB. You can clearly see the winner in this case. DayJS has done a good job.

DayJS a new alternative to MomentJS

Performance

We tried to do two performance test on both library and here are the results.

Parse an ISO date and format it

MomentJS took 1.6949999990174547 milliseconds
DayJS took 0.3600000054575503 milliseconds

Parse an ISO date and get seconds from it

MomentJS took 0.6649999995715916 milliseconds
DayJS took 0.22000000171829015 milliseconds

You can clearly see DayJS is 3 times faster then MomentJS.

Browser supports

MomentJS supports the following browsers are used for the ci system: Chrome on Windows XP, IE 8, 9, and 10 on Windows 7, IE 11 on Windows 10, latest Firefox on Linux, and latest Safari on OSX 10.8 and 10.11.

Whereas DayJS supports all browsers.

Syntax

DayJS uses syntax of MomentJS. If you had used MomentJS earlier then you already know how to use DayJS.

dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss');

In the end you can see clearly a winner i.e DayJS. If you are going to start a new Project then you should give a chance to DayJS.

Ref

How to block +,- and e in Number Input

Categories: Reactjs

1 Comment

Best svg resources for React Projects - Blog React · June 26, 2020 at 3:36 am

[…] DayJS a new alternative to MomentJS Categories: Reactjs Tags: Reactjs Advanced […]

Comments are closed.