相对时间
RelativeTime 为格式化日期为相对时间字符串(例如 3 小时前)添加了 .from .to .fromNow .toNow API。
var relativeTime = require('dayjs/plugin/relativeTime')
dayjs.extend(relativeTime)
dayjs().from(dayjs('1990-01-01')) // in 31 years
dayjs().from(dayjs('1990-01-01'), true) // 31 years
dayjs().fromNow()
dayjs().to(dayjs('1990-01-01')) // "31 years ago"
dayjs().toNow()
距现在的时间 .fromNow(withoutSuffix?: boolean)
返回距现在的相对时间的 string。
距 X 的时间 .from(compared: Dayjs, withoutSuffix?: boolean)
返回距 X 的相对时间的 string。
距现在的时间 .toNow(withoutSuffix?: boolean)
返回相对于现在的相对时间字符串。
时间到 X .to(compared: Dayjs, withoutSuffix?: boolean)
返回相对于 X 的相对时间字符串。
