Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Dayjs

Index

Constructors

constructor

  • new Dayjs(config?: string | number | Date | Dayjs): Dayjs
  • Parameters

    • Optional config: string | number | Date | Dayjs

    Returns Dayjs

Methods

add

  • Returns a cloned Day.js object with a specified amount of time added.

    dayjs().add(7, 'day')// => Dayjs
    

    Units are case insensitive, and support plural and short forms.

    Parameters

    Returns Dayjs

clone

  • All Day.js objects are immutable. Still, dayjs#clone can create a clone of the current object if you need one.

    dayjs().clone()// => Dayjs
    dayjs(dayjs('2019-01-25')) // passing a Dayjs object to a constructor will also clone it

    Docs: https://day.js.org/docs/en/parse/dayjs-clone

    Returns Dayjs

date

  • date(): number
  • date(value: number): Dayjs

day

  • day(): number
  • day(value: number): Dayjs
  • Get the day of the week.

    Returns numbers from 0 (Sunday) to 6 (Saturday).

    dayjs().day()// 0-6
    

    Docs: https://day.js.org/docs/en/get-set/day

    Returns number

  • Set the day of the week.

    Accepts numbers from 0 (Sunday) to 6 (Saturday). If the range is exceeded, it will bubble up to other weeks.

    dayjs().day(0)// => Dayjs
    

    Docs: https://day.js.org/docs/en/get-set/day

    Parameters

    • value: number

    Returns Dayjs

daysInMonth

  • daysInMonth(): number

diff

  • diff(date: string | number | Date | Dayjs, unit?: "M" | "date" | "s" | "y" | "millisecond" | "second" | "minute" | "hour" | "day" | "month" | "year" | "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "months" | "years" | "dates" | "d" | "h" | "m" | "ms" | "week" | "weeks" | "w" | "quarter" | "quarters" | "Q", float?: boolean): number
  • This indicates the difference between two date-time in the specified unit.

    To get the difference in milliseconds, use dayjs#diff

    const date1 = dayjs('2019-01-25')
    const date2 = dayjs('2018-06-05')
    date1.diff(date2) // 20214000000 default milliseconds

    To get the difference in another unit of measurement, pass that measurement as the second argument.

    const date1 = dayjs('2019-01-25')
    date1.diff('2018-06-05', 'month') // 7

    Units are case insensitive, and support plural and short forms.

    Docs: https://day.js.org/docs/en/display/difference

    Parameters

    • date: string | number | Date | Dayjs
    • Optional unit: "M" | "date" | "s" | "y" | "millisecond" | "second" | "minute" | "hour" | "day" | "month" | "year" | "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "months" | "years" | "dates" | "d" | "h" | "m" | "ms" | "week" | "weeks" | "w" | "quarter" | "quarters" | "Q"
    • Optional float: boolean

    Returns number

endOf

  • Returns a cloned Day.js object and set it to the end of a unit of time.

    dayjs().endOf('month')// => Dayjs
    

    Units are case insensitive, and support plural and short forms.

    Parameters

    Returns Dayjs

format

  • format(template?: string): string
  • Get the formatted date according to the string of tokens passed in.

    To escape characters, wrap them in square brackets (e.g. [MM]).

    dayjs().format()// => current date in ISO8601, without fraction seconds e.g. '2020-04-02T08:02:17-05:00'
    dayjs('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]')// 'YYYYescape 2019-01-25T00:00:00-02:00Z'
    dayjs('2019-01-25').format('DD/MM/YYYY') // '25/01/2019'

    Docs: https://day.js.org/docs/en/display/format

    Parameters

    • Optional template: string

    Returns string

from

  • from(compared: string | number | Date | Dayjs, withoutSuffix?: boolean): string
  • Parameters

    • compared: string | number | Date | Dayjs
    • Optional withoutSuffix: boolean

    Returns string

fromNow

  • fromNow(withoutSuffix?: boolean): string
  • Parameters

    • Optional withoutSuffix: boolean

    Returns string

get

  • String getter, returns the corresponding information getting from Day.js object.

    In general:

    dayjs().get(unit) === dayjs()[unit]()
    

    Units are case insensitive, and support plural and short forms.

    dayjs().get('year')
    dayjs().get('month') // start 0
    dayjs().get('date')

    Docs: https://day.js.org/docs/en/get-set/get

    Parameters

    Returns number

hour

  • hour(): number
  • hour(value: number): Dayjs

isAfter

  • This indicates whether the Day.js object is after the other supplied date-time.

    dayjs().isAfter(dayjs('2011-01-01')) // default milliseconds
    

    If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter.

    dayjs().isAfter('2011-01-01', 'year')// => boolean
    

    Units are case insensitive, and support plural and short forms.

    Parameters

    Returns boolean

isBefore

  • This indicates whether the Day.js object is before the other supplied date-time.

    dayjs().isBefore(dayjs('2011-01-01')) // default milliseconds
    

    If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter.

    dayjs().isBefore('2011-01-01', 'year')// => boolean
    

    Units are case insensitive, and support plural and short forms.

    Parameters

    Returns boolean

isSame

  • This indicates whether the Day.js object is the same as the other supplied date-time.

    dayjs().isSame(dayjs('2011-01-01')) // default milliseconds
    

    If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter.

    dayjs().isSame('2011-01-01', 'year')// => boolean
    

    Docs: https://day.js.org/docs/en/query/is-same

    Parameters

    Returns boolean

isValid

  • isValid(): boolean
  • This returns a boolean indicating whether the Day.js object contains a valid date or not.

    dayjs().isValid()// => boolean
    

    Docs: https://day.js.org/docs/en/parse/is-valid

    Returns boolean

locale

  • locale(): string
  • locale(preset: string | ILocale, object?: Partial<ILocale>): Dayjs
  • Returns string

  • Parameters

    • preset: string | ILocale
    • Optional object: Partial<ILocale>

    Returns Dayjs

millisecond

  • millisecond(): number
  • millisecond(value: number): Dayjs

minute

  • minute(): number
  • minute(value: number): Dayjs

month

  • month(): number
  • month(value: number): Dayjs
  • Get the month.

    Months are zero indexed, so January is month 0.

    dayjs().month()// => 0-11
    

    Docs: https://day.js.org/docs/en/get-set/month

    Returns number

  • Set the month.

    Months are zero indexed, so January is month 0.

    Accepts numbers from 0 to 11. If the range is exceeded, it will bubble up to the year.

    dayjs().month(0)// => Dayjs
    

    Docs: https://day.js.org/docs/en/get-set/month

    Parameters

    • value: number

    Returns Dayjs

second

  • second(): number
  • second(value: number): Dayjs
  • Get the seconds.

    dayjs().second()// => 0-59
    

    Docs: https://day.js.org/docs/en/get-set/second

    Accepts numbers from 0 to 59. If the range is exceeded, it will bubble up to the minutes.

    dayjs().second(1)// Dayjs
    

    Returns number

  • Set the seconds.

    Accepts numbers from 0 to 59. If the range is exceeded, it will bubble up to the minutes.

    dayjs().second(1)// Dayjs
    

    Parameters

    • value: number

    Returns Dayjs

set

  • Generic setter, accepting unit as first argument, and value as second, returns a new instance with the applied changes.

    In general:

    dayjs().set(unit, value) === dayjs()[unit](value)
    

    Units are case insensitive, and support plural and short forms.

    dayjs().set('date', 1)
    dayjs().set('month', 3) // April
    dayjs().set('second', 30)

    Docs: https://day.js.org/docs/en/get-set/set

    Parameters

    Returns Dayjs

startOf

  • Returns a cloned Day.js object and set it to the start of a unit of time.

    dayjs().startOf('year')// => Dayjs
    

    Units are case insensitive, and support plural and short forms.

    Parameters

    Returns Dayjs

subtract

  • Returns a cloned Day.js object with a specified amount of time subtracted.

    dayjs().subtract(7, 'year')// => Dayjs
    

    Units are case insensitive, and support plural and short forms.

    Parameters

    Returns Dayjs

to

  • to(compared: string | number | Date | Dayjs, withoutSuffix?: boolean): string
  • Parameters

    • compared: string | number | Date | Dayjs
    • Optional withoutSuffix: boolean

    Returns string

toDate

  • toDate(): Date
  • To get a copy of the native Date object parsed from the Day.js object use dayjs#toDate.

    dayjs('2019-01-25').toDate()// => Date
    

    Returns Date

toISOString

  • toISOString(): string

toJSON

  • toJSON(): string

toNow

  • toNow(withoutSuffix?: boolean): string
  • Parameters

    • Optional withoutSuffix: boolean

    Returns string

toString

  • toString(): string
  • Returns a string representation of the date.

    dayjs('2019-01-25').toString() // 'Fri, 25 Jan 2019 02:00:00 GMT'
    

    Docs: https://day.js.org/docs/en/display/as-string

    Returns string

unix

  • unix(): number
  • This returns the Unix timestamp (the number of seconds since the Unix Epoch) of the Day.js object.

    dayjs('2019-01-25').unix() // 1548381600
    

    This value is floored to the nearest second, and does not include a milliseconds component.

    Returns number

utcOffset

  • utcOffset(): number

valueOf

  • valueOf(): number
  • This returns the number of milliseconds since the Unix Epoch of the Day.js object.

    dayjs('2019-01-25').valueOf() // 1548381600000
    +dayjs(1548381600000) // 1548381600000

    To get a Unix timestamp (the number of seconds since the epoch) from a Day.js object, you should use Unix Timestamp dayjs#unix().

    Returns number

year

  • year(): number
  • year(value: number): Dayjs

Generated using TypeDoc