Lightweight Date & Time Manipulation Library – dayjs

Category: Date & Time , Javascript , Recommended | December 6, 2022
Author:xx45
Views Total:255 views
Official Page:Go to website
Last Update:December 6, 2022
License:MIT

Preview:

Lightweight Date & Time Manipulation 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
  • arraySupport
  • 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.11.7 (12/06/2022)

  • Bug Fixes

v1.11.6 (10/20/2022)

  • Bug Fixes

v1.11.5 (08/13/2022)

  • Bug Fixes

v1.11.4 (07/20/2022)

  • Bug Fixes

v1.11.3 (06/05/2022)

  • Bug Fixes

v1.11.2 (05/06/2022)

  • Bug Fixes

v1.11.1 (04/15/2022)

  • add Bengali (Bangladesh) [bn-bd] locale
  • refactor replace deprecated String.prototype.substr()
  • Update German [de] locale, adds the abbreviations for month including a . in the end, as in September -> Sept.
  • update Italian (Switzerland) [it-ch] locale relativeTime
  • update Kurdish [ku] locale strings and formatted output contains non-standard kurdish characters
  • update locale bo [Tibetan]: corrected the orders in formats

v1.11.0 (03/15/2022)

  • Fallback to language only locale + support uppercase locales
  • Bugfix

v1.10.8 (02/28/2021)

  • set locale pt, pt-br correct weekdays and months

v1.10.7 (09/10/2021)

  • Bug Fixes

v1.10.6 (07/06/2021)

  • Bug Fixes

v1.10.5 (05/26/2021)

  • Bug Fixes

v1.10.4 (01/22/2021)

  • Correct handling negative duration
  • Improve Duration types
  • parse a string for MMM month format with underscore delimiter
  • Update Bengali [bn] locale
  • update locale Portuguese [pt] yearStart
  • update Polish [pl] locale yearStart
  • Update Slovenian [sl] relativeTime locale

v1.10.3 (01/09/2021)

  • fix customParseFormat plugin strict mode parse meridiem bug
  • fix weekYear plugin missing locale bug
  • update advancedFormat plugin to add format options for iso week and weekyear
  • update devHelper to add dev warning setting locale before loading
  • update German [de] locale yearStart

v1.10.2 (01/06/2021)

  • fix parse regex bug
  • remove module entry in package.json to revert 1.10.1 change
  • update devHelper add warning “passing Year as a Number will be parsed as a Unix timestamp”

v1.10.1 (01/03/2021)

  • fix typescript type error UnitTypeLongPlural

v1.10.0 (01/03/2021)

  • Bug Fixes
  • Add ES6 Module Support, package.json module point to “esm/index.js”

v1.9.8 (12/27/2020)

  • Bug Fixes

v1.9.7 (12/06/2020)

  • Bug Fixes

v1.9.6 (11/10/2020)

  • fix customParseFormat plugin parsing date bug
  • Update lv (Latvian) locale relative time

v1.9.5 (11/05/2020)

  • Bug Fixes

v1.9.4 (10/23/2020)

  • Bug Fixes

v1.9.3 (10/13/2020)

  • fix localizedFormat export error

v1.9.2 (10/13/2020)

  • add arraySupport plugin
  • export type of duration plugin
  • Fix LocaleData plugin longDateFormat lowercase error
  • Fix objectSupport plugin bug in UTC
  • fix Serbian locale grammar (sr, sr-cyrl)
  • Fix typo for “monday” in arabic
  • support dayjs.add(Duration), dayjs.subtract(Duration)
  • update Breton [br] locale relativeTime config
  • update Catalan [ca] locale ordinal
  • update German [de] locale relativeTime config
  • update localeData plugin to add longDateFormat to global localeData
  • Update objectSupport plugin to return current date time while parsing empty object

v1.9.1 (09/28/2020)

  • Fix objectSupport plugin to get the correct result (zero-based month)

v1.9.0 (09/28/2020)

  • Add setDefault typing to timezone.d.ts
  • fix DST bug in utc plugin
  • Fix optional type for timezone plugin
  • Fix timezone plugin conversion bug
  • update duration plugin type file
  • update timezone plugin to support getting offset name e.g. EST
  • update utc plugin to support keepLocalTime .utc(true)
  • Correct casing for en-sg locale name

v1.8.36 (09/17/2020)

  • Bug Fixes

v1.8.35 (09/02/2020)

  • Fix BadMutable plugin bug in .diff
  • fix LocaleData plugin to support instance.weekdays() API
  • Update Dutch (nl) locale to set correct yearStart

v1.8.34 (08/20/2020)

  • Fix Timezone plugin to preserve milliseconds while changing timezone
  • support parsing unlimited decimals of millisecond
  • update Duration plugin to support global locale

v1.8.33 (08/10/2020)

  • Add PluralGetSet plugin for plural getters/setters
  • Add typescript type defs in esm build
  • Fix isoWeek Plugin cal bug in UTC mode
  • Fix Timezone plugin parsing js date, Day.js object, timestamp bug && update type file
  • Fix Timezone plugin UTCOffset rounding bug
  • Fix UTC plugin bug while comparing an utc instance to a local one
  • Update pt-br locale weekStart 0

v1.8.32 (08/04/2020)

  • Add Experimental Timezone Plugin
  • fix parse date string error e.g. ‘2020/9/30’
  • update monthDiff function to get more accurate results
  • Update UTC plugin to support keepLocalTime

v1.8.31 (07/29/2020)

  • Rollback LocalePresetType to string
  • Update Regex to parse ‘YYYY’ correctly

v1.8.30 (07/22/2020)

  • Add Haitian Creole (ht) and Spanish Puerto Rico (es-pr) locale configs
  • Fix UTC plugin wrong hour bug while adding month or year
  • Update French (fr) locale to set correct yearStart

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