Day.js - JavaScript time processing library

Introduction to Day.js

  In terms of using JavaScript to process time, Moment.js is used, but it is too heavy, with more than 200 k, and only a few APIs may be used in general projects. Therefore, a lightweight time library is recommended here - Day .js. You can see that there are nearly 7k stars on the github address , indicating that it is still relatively popular. Here is an example of use:

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

  That is, it supports chained calls, and it is very convenient to set up. It has the same API and usage as Moment.js, and it is immutable data and compatible with all browsers.  

  

Day.js installation

  There are various installation methods, that is, the general npm or cdn. The npm installation is as follows:

npm install dayjs --save

  Use as follows:

var dayjs = require('dayjs');
dayjs().format();

 

  Using cdn, you can import it directly through script:

<!-- Latest compiled and minified JavaScript -->
<script src="https://unpkg.com/dayjs"></script>
<script>
  dayjs().format();
</script>

 

 

Related API

  You can view the Day.js Chinese documentation .

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325132535&siteId=291194637