Get the day of the week.
Returns numbers from 0 (Sunday) to 6 (Saturday).
dayjs().day()// 0-6
Set the day of the week.
Accepts numbers from 0 (Sunday) to 6 (Saturday). If the range is exceeded, it will bubble up to next weeks.
dayjs().day(0)// => Dayjs
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
date1.diff() // milliseconds to current time
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.
Optional
date: ConfigTypeOptional
unit: Optional
float: booleanGet 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'
Optional
template: stringString 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')
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.
Optional
date: ConfigTypeOptional
unit: OpUnitTypeThis 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.
Optional
date: ConfigTypeOptional
unit: OpUnitTypeThis 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
Optional
date: ConfigTypeOptional
unit: OpUnitTypeGet the milliseconds.
dayjs().millisecond()// => 0-999
Set the milliseconds.
Accepts numbers from 0 to 999. If the range is exceeded, it will bubble up to the next seconds.
dayjs().millisecond(1)// => Dayjs
Get the month.
Months are zero indexed, so January is month 0.
dayjs().month()// => 0-11
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 next year.
dayjs().month(0)// => Dayjs
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)
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.
Optional
unit: ManipulateTypeThis 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()
.
Docs: https://day.js.org/docs/en/display/unix-timestamp-milliseconds
Returns a cloned Day.js object with a specified amount of time added.
Units are case insensitive, and support plural and short forms.
Docs: https://day.js.org/docs/en/manipulate/add