时间差 · Day.js 中文网

时间差 · Day.js 中文网

这表示指定单位中两个日期时间之间的差异。

¥This indicates the difference between two date-time in the specified unit.

要获得以毫秒为单位的差异,请使用 dayjs#diff。

¥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

默认情况下,dayjs#diff 会将结果截断为零位小数,返回一个整数。如果你想要浮点数,请传递 true 作为第三个参数。

¥By default, dayjs#diff will truncate the result to zero decimal places, returning an integer. If you want a floating point number, pass true as the third argument.

const date1 = dayjs('2019-01-25')

date1.diff('2018-06-05', 'month', true) // 7.645161290322581

所有可用单位的列表

¥List of all available units

单位不区分大小写,并支持复数和缩写形式。请注意,缩写形式区分大小写。

¥Units are case insensitive, and support plural and short forms. Note, short forms are case sensitive.

单位速记描述

dayd天

weekw周

quarterQ季度

monthM月份(1 月为 0,12 月为 11)

yeary年份

hourh小时

minutem分钟

seconds秒

millisecondms毫秒

相关文章

人死后骨头多少年腐烂完毕
beat365中文版

人死后骨头多少年腐烂完毕

📅 11-14 👁️ 3289
1美元兑人民币金额
beat365中文版

1美元兑人民币金额

📅 10-07 👁️ 7263