RelativeTime
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 Returns the string
of relative time from now.
.from(compared: Dayjs, withoutSuffix?: boolean)
Time from X Returns the string
of relative time from X.
.toNow(withoutSuffix?: boolean)
Time to now Returns the string
of relative time to now.
.to(compared: Dayjs, withoutSuffix?: boolean)
Time to X Returns the string
of relative time to X.