Moment.js is a large and complete JS time library that makes it very easy to handle dates and times. However, moment.js is too heavy (200K + with locals) and probably only uses a few of its usual apis. While the community also has several lightweight time pools, moving past can add new learning and migration costs.

If only there were a library with the same syntax, functionality, and weight as moment.js!

Day.js is a lightweight JavaScript time and date library that keeps the same API design as moment. js. If you’ve ever used moment.js, do you already know how to use day.js

The basic usage of day.js is as follows, same API, same chain operation.

dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss');
Copy the code
  • 🕒 has the same API and usage as moment.js
  • 💪 Immutable data
  • 🔥 Support Chainable operation
  • 🌐 I18n internationalization
  • 📦 a tiny library only 2KB in size
  • 👫 Full browser compatibility

Day.js is only 2KB in size, but its functionality is not at all emasculated. Contains all common methods of time processing.


Document address (Chinese)💖

If you like, may I give you 💖star💖? github.com/iamkun/dayj…



If you don’t have the need to localize other languages in your project, 1.6.0 supports multi-language internationalization and loads languages on demand. To reduce the size of the package and improve the development experience, just replace(/moment/g, ‘dayjs’) globally. From moment.js + locals 200KB to dayjs 2KB. All API calls remain unchanged and do not need to be modified.

Take a look at the Dayjs syntax, isn’t it nice 😋 (yes that’s the syntax for moment)

create

Dayjs () // The current time'1995-12-25'Dayjs (date.now () -24 * 60 * 60 * 1000) // yesterdayCopy the code

formatting

dayjs().format('YYYy-mm-DD' HH: MM :ss'// 2018 aug 08 00:00:00 dayjs().format('[YYYY]') / /"[2018].". [] will be output as is.Copy the code

operation

dayjs().add(7, 'days'Dayjs ().subtract(1,'months'// last month dayjs().startof ()'months') // Get dayjs().endof ('year') // Get the end of the yearCopy the code

The query

dayjs('2010-10-20').isBefore('2010-10-21') // Before dayjs('2010-10-20').isAfter('2010-10-19') // later than dayjs().isleapYear () // leap yearCopy the code

issue and pr’s welcome

Welcome to issue and PR oh github.com/iamkun/dayj…