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.
.from(compared: Dayjs, withoutSuffix?: boolean)
时间从 X ¥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.
.to(compared: Dayjs, withoutSuffix?: boolean)
的时间
到 X ¥Time to X .to(compared: Dayjs, withoutSuffix?: boolean)
返回相对于 X 的时间的 string
。
¥Returns the string
of relative time to X.