RelativeTime
relativeTime 添加了 .from .to .fromNow .toNow API 将日期格式化为相对时间字符串(例如 3 小时前)。
¥RelativeTime adds .from .to .fromNow .toNow APIs to formats date to relative time strings (e.g. 3 hours ago).
var relativeTime = require("dayjs/plugin/relativeTime");
// import relativeTime from 'dayjs/plugin/relativeTime' // ES 2015
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)
¥Time from now .fromNow(withoutSuffix?: boolean)
返回从现在开始的相对时间的 string。
¥Returns the string of relative time from now.
时间从 X .from(compared: Dayjs, withoutSuffix?: boolean)
¥Time from X .from(compared: Dayjs, withoutSuffix?: boolean)
返回相对于 X 的时间的 string。
¥Returns the string of relative time from X.
到现在 .toNow(withoutSuffix?: boolean)
¥Time to now .toNow(withoutSuffix?: boolean)
返回到现在为止的相对时间 string。
¥Returns the string of relative time to now.
到 X .to(compared: Dayjs, withoutSuffix?: boolean) 的时间
¥Time to X .to(compared: Dayjs, withoutSuffix?: boolean)
返回相对于 X 的时间的 string。
¥Returns the string of relative time to X.
