RelativeTime
relativeTime 添加了 `.from` `.to` `.fromNow` `.toNow` API 将日期格式化为相对时间字符串(例如 3 小时前)。
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
。
.from(compared: Dayjs, withoutSuffix?: boolean)
时间从 X 返回相对于 X 的时间的 string
。
.toNow(withoutSuffix?: boolean)
到现在 返回到现在为止的相对时间 string
。
.to(compared: Dayjs, withoutSuffix?: boolean)
的时间
到 X 返回相对于 X 的时间的 string
。