dayjs
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Day.js serves as a powerful yet minimalist JavaScript library that is optimized for parsing, validating, manipulating, and showcasing dates and times for modern browsers. What sets Day.js apart is its Moment.js-compatible API and compact 2KB size, which makes it a nifty yet lightweight alternative to Moment.js. It supports all types of browsers, and its familiar Moment.js API and patterns, immutability in nature, chainability, and internationalization support make it a handy tool for developers.
To use Day.js, you first need to install it in your JavaScript project with the npm command npm install dayjs --save
. Once installed, you can utilize its API to perform a variety of actions on dates and times. Here are a few examples:
Parsing a date:
dayjs('2018-08-08')
Displaying date:
dayjs().format('{YYYY} MM-DDTHH:mm:ss SSS [Z] A')
Getting and setting dates:
dayjs().set('month', 3).month()
Manipulating dates:
dayjs().add(1, 'year')
Querying dates:
dayjs().isBefore(dayjs())
Day.js also supports internationalization:
import 'dayjs/locale/es' // load on demand
dayjs.locale('es') // use Spanish locale globally
dayjs('2018-05-05').locale('zh-cn').format() // use Chinese Simplified locale in specific instance
And you can extend its functionality using plugins:
import advancedFormat from 'dayjs/plugin/advancedFormat' // load on demand
dayjs.extend(advancedFormat) // use plugin
dayjs().format('Q Do k kk X x') // more available formats
The complete documentation, API references, and other related Day.js docs can be found on the day.js.org website. This website hosts an array of information about Day.js, ranging from API usage and command instructions to plugin information and internationalization instructions.