Skip to content
Day.js

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

Appearance

Sidebar Navigation

Installation

Node.js

Browser

TypeScript

Download

Parse

Now

String

String + Format

Unix Timestamp (milliseconds)

Unix Timestamp (seconds)

Date

Object

Array

UTC

Dayjs Clone

Validation

Get + Set

Millisecond

Second

Minute

Hour

Date of Month

Day of Week

Day of Week (Locale Aware)

ISO Day of Week

Day of Year

Week of Year

Week of Year (ISO)

Month

Quarter

Year

Week Year

Week Year (ISO)

Weeks In Year (ISO)

Get

Set

Maximum

Minimum

Manipulate

Add

Subtract

Start of Time

End of Time

Local

UTC

UTC offset

Display

Format

Time from now

Time from X

Time to now

Time to X

Calendar Time

Difference

Unix Timestamp (milliseconds)

Unix Timestamp

Days in Month

As Javascript Date

As Array

As JSON

As ISO 8601 String

As Object

As String

Query

Is Before

Is Same

Is After

Is Same or Before

Is Same or After

Is Between

Is a Dayjs

Is Leap Year

i18n

Loading locale in NodeJS

Loading locale in the browser

Changing locale globally

Changing locales locally

Checking the current Day.js locale

Listing the months and weekdays of the current locale

Accessing locale specific functionality

Plugins

Loading plugin in NodeJS

Loading plugin in the browser

AdvancedFormat

ArraySupport

BadMutable

BigIntSupport

BuddhistEra

Calendar

CustomParseFormat

DayOfYear

DevHelper

Duration

IsBetween

IsLeapYear

IsSameOrAfter

IsSameOrBefore

IsToday

IsTomorrow

IsYesterday

IsoWeek

IsoWeeksInYear

LocaleData

LocalizedFormat

MinMax

ObjectSupport

PluralGetSet

PreParsePostFormat

QuarterOfYear

RelativeTime

Timezone

ToArray

ToObject

UpdateLocale

UTC

weekOfYear

WeekYear

Weekday

Customize

Month Names

Month Abbreviations

Weekday Names

Weekday Abbreviations

Minimal Weekday Abbreviations

Relative Time

Calendar

Durations

Creating

Clone

Humanize

Format

Milliseconds

Seconds

Minutes

Hours

Days

Weeks

Months

Years

Add Time

Subtract Time

Using Duration with Diff

As Unit of Time

Get Unit of Time

As JSON

Is a Duration

As ISO 8601 String

Locale

Time Zone

Parsing in Zone

Converting to Zone

Guessing user zone

Set Default Timezone

On this page

Customize ​

Day.js is very easy to customize.

You can create a new locale.

js
var localeObject = {...} // Day.js locale Object, detailed below
dayjs.locale('en-my-settings', localeObject);

Update an existing locale.

TIP

This requires the UpdateLocale plugin to work

js
dayjs.extend(updateLocale);

dayjs.updateLocale('en', {
  /**/
});

Template of a Day.js locale Object.

javascript
const localeObject = {
  name: 'es', // name String
  weekdays: 'Domingo_Lunes ...'.split('_'), // weekdays Array
  weekdaysShort: 'Sun_M'.split('_'), // OPTIONAL, short weekdays Array, use first three letters if not provided
  weekdaysMin: 'Su_Mo'.split('_'), // OPTIONAL, min weekdays Array, use first two letters if not provided
  weekStart: 1, // OPTIONAL, set the start of a week. If the value is 1, Monday will be the start of week instead of Sunday。
  yearStart: 4, // OPTIONAL, the week that contains Jan 4th is the first week of the year.
  months: 'Enero_Febrero ... '.split('_'), // months Array
  monthsShort: 'Jan_F'.split('_'), // OPTIONAL, short months Array, use first three letters if not provided
  ordinal: n => `${n}º`, // ordinal Function (number) => return number + output
  formats: {
    // abbreviated format options allowing localization
    LTS: 'h:mm:ss A',
    LT: 'h:mm A',
    L: 'MM/DD/YYYY',
    LL: 'MMMM D, YYYY',
    LLL: 'MMMM D, YYYY h:mm A',
    LLLL: 'dddd, MMMM D, YYYY h:mm A',
    // lowercase/short, optional formats for localization
    l: 'D/M/YYYY',
    ll: 'D MMM, YYYY',
    lll: 'D MMM, YYYY h:mm A',
    llll: 'ddd, MMM D, YYYY h:mm A',
  },
  relativeTime: {
    // relative time format strings, keep %s %d as the same
    future: 'in %s', // e.g. in 2 hours, %s been replaced with 2hours
    past: '%s ago',
    s: 'a few seconds',
    m: 'a minute',
    mm: '%d minutes',
    h: 'an hour',
    hh: '%d hours', // e.g. 2 hours, %d been replaced with 2
    d: 'a day',
    dd: '%d days',
    M: 'a month',
    MM: '%d months',
    y: 'a year',
    yy: '%d years',
  },
  meridiem: (hour, minute, isLowercase) => {
    // OPTIONAL, AM/PM
    return hour > 12 ? 'PM' : 'AM';
  },
};

Template of a Day.js locale file (e.g dayjs/locale/es.js).

javascript
import dayjs from 'dayjs'

const locale = { ... } // Your Day.js locale Object.

dayjs.locale(locale, null, true) // load locale for later use

export default locale
Pager
Previous pageWeekday
Next pageMonth Names

Released under the MIT License.

Copyright (c) 2020 iamkun

https://day.js.org/docs/en/customization/customization

Released under the MIT License.

Copyright (c) 2020 iamkun