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 ?
Let’s try to do comparison of both library based on performance, size, browser support, usage etc.
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.
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.
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.
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.