Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the advantages of Day.js

Shulou Source: shulou.com Published: 2022-06-03 06:13:35 10月03日 Update

This article mainly explains "what are the advantages of Day.js". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the advantages of Day.js".

In previous ReactNative development work, time and date-related operations such as formatting, adding or subtracting values are carried out through the Moment.js library.

Moment.js is a very powerful and complete date processing tool, but the relative size is also relatively large (200k + with locals). But in general, only a few of the commonly used API are used in the project, which is somewhat overqualified.

If there is one as powerful as moment and can meet our business needs, and the size is still small, that is the best.

After all, there is a market where there is need, and Day.js arises at the historic moment.

Day.js has the following advantages:

2kB

Download, parse, and execute less JavaScript, leaving more time for your code.

Simple and easy

Day.js is a lightweight JavaScript library for processing times and dates, which remains exactly the same as Moment.js 's API design.

If you have ever used Moment.js, you already know how to use Day.js.

Immutable

All API operations will return a new Dayjs object.

This design can avoid the generation of bug and save debugging time.

Internationalization

Day.js supports internationalization well. But unless loaded manually, multilingual languages are not packaged into the project by default

Install and reference yarn add dayjs

Import dayjs from "dayjs"; commonly used APIdayjs ('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 ()) Thank you for your reading. The above is the content of "what are the advantages of Day.js?" after the study of this article, I believe you have a deeper understanding of what the advantages of Day.js are, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Advantages time date learning strength volume content international that is commonly used situation more processing design good overkill arises at the historic moment business code function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi vpn NVidia macOS