Lightweight Date & Time Nanipulation Library – dayjs

Category: Date & Time , Javascript , Recommended | May 28, 2020
Author: xx45
Views Total: 37 views
Official Page: Go to website
Last Update: May 28, 2020
License: MIT

Preview:

Lightweight Date & Time Nanipulation Library – dayjs

Description:

dayjs is a blazing-fast,  ultra-light (2kb) alternative to the moment.js library that helps you parse, validate, manipulate, and display dates and times in pure JavaScript.

Install & Import:

# NPM
$ npm install dayjs --save

Import the dayjs library into your project.

<!-- Node.js -->
var dayjs = require('dayjs');
<!-- Typescript -->
import * as dayjs from 'dayjs'
<!-- Browser -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dayjs.min.js"></script>

Import locals. You can find all locals here.

require('dayjs/locale/de')
<!-- Browser --> 
<script src="https://cdn.jsdelivr.net/npm/[email protected]/locale/de.js"></script>

Import plugins if needs. All possible plugins:

  • AdvancedFormat
  • BuddhistEra
  • Calendar
  • CustomParseFormat
  • DayOfYear
  • Duration
  • IsBetween
  • IsLeapYear
  • IsSameOrAfter
  • IsSameOrBefore
  • IsToday
  • IsTomorrow
  • IsYesterday
  • IsoWeek
  • IsoWeeksInYear
  • LocaleData
  • LocalizedFormat
  • MinMax
  • QuarterOfYear
  • RelativeTime
  • ToArray
  • ToObject
  • UpdateLocale
  • UTC
  • WeekDay
  • weekOfYear
  • WeekYear
var PlugiName = require('dayjs/plugin/pluginname')
<!-- Browser -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/plugin/pluginname.js"></script>

Usage:

All the API are similar to the Moment.js, just replace the ‘moment’ with ‘dayjs’ as follows. You can find the full API here.

// parse
dayjs('2018-12-21') 

// display
dayjs().format('{YYYY} MM-DDTHH:mm:ss SSS [Z] A')

// get & set
dayjs().set('month', 3).month() 

// manipulate
dayjs().add(1, 'year') 

// query
dayjs().isBefore(dayjs())

// set local
dayjs().locale('de')

Changelog:

v1.8.28 (05/28/2020)

  • Bugfixes

v1.8.27 (05/14/2020)

  • Add Kinyarwanda (rw) locale
  • Add plugin objectSupport
  • Add Turkmen (tk) locale
  • Fix CustomParseFormat plugin set locale error
  • Fix locale month function bug
  • Update CustomParseFormat plugin to support Array formats

v1.8.26 (04/30/2020)

  • Fix Duration plugin .toISOString format bug
  • Fix WeekOfYear plugin bug while using BadMutable plugin
  • Update CustomParseFormat plugin strict mode
  • Update RelativeTime plugin default config

v1.8.25 (04/21/2020)

  • Fix CustomParseFormat plugin of parsing only YYYY / YYYY-MM bug
  • Fix Duration plugin get seconds
  • Fix type definition of locale
  • Fix UTC plugin startOf, endOf bug

v1.8.24 (04/10/2020)

  • Add config option to RelativeTime plugin
  • Add Duration plugin
  • Add en-in, en-tt locales
  • add isToday, isTomorrow, isYesterday plugins
  • Add option callback to Calendar plugin
  • Fix monthsShort for locale fr
  • Update Breton locale (br) meridiem config
  • Update Ukrainian (uk) locale relative time

v1.8.23 (03/16/2020)

  • Bug Fixes

v1.8.22 (03/08/2020)

  • Bug Fixes

v1.8.20 (02/26/2020)

  • Bug Fixes

v1.8.20 (01/20/2020)

  • Bug Fixes

v1.8.19 (01/06/2020)

  • Add UpdateLocale plugin to update a locale’s properties
  • Fix CustomParseFormat Plugin ‘YYYY-MM’ use first day of the month
  • Fix CustomParseFormat Plugin to set correct locale
  • Fix WeekOfYear Plugin wrong calender week number bug
  • Update RelativeTime plugin to support function to make additional processing
  • Update ru, uk, cs locale to support relativeTime with plural

v1.8.18 (12/22/2019)

  • Tons of bugs fixed.

v1.8.11 (03/23/2019)

  • Add .add(‘quarter’) .startOf(‘quarter’) through plugin quarterOfYear
  • Add locale support for Azerbaijani language (az)
  • Correct typescript definition add
  • Fix CustomParseFormat plugin formatting bug

v1.8.9 (03/06/2019)

  • Add de-AT locale
  • Add UTC mode with UTC plugin
  • Adding locale zh-hk

03/05/2019

  • v1.8.8: Update relativeTime plugin

12/28/2018

  • Invalid date format return `Invalid date`

12/21/2018

  • v1.7.8: bugfix

06/14/2018

  • v1.6.9: bugfix

06/11/2018

  • v1.6.7: bugfix

You Might Be Interested In:


Leave a Reply