从此刻到过去的时间
返回从现在开始的相对时间的字符串。
¥Returns the string of relative time from now.
This requires the
RelativeTime
plugin to work
dayjs.extend(relativeTime)
dayjs('1999-01-01').fromNow() // 22 years ago
如果传递 true,则可以获得不带后缀的值。
¥If you pass true, you can get the value without the suffix.
dayjs.extend(relativeTime)
dayjs('1999-01-01').fromNow(true) // 22 years
细分范围一览表
¥List of breakdown range
基本字符串由当前区域设置和 可以定制 本地化。时间四舍五入到最接近的秒数。
¥The base strings are localized by the current locale and can be customized. Time is rounded to the nearest second.
范围 | 键 | 示例输出 |
---|---|---|
0 到 44 秒 | s | 几秒钟前 |
45 至 89 秒 | m | a minute ago |
90 秒到 44 分钟 | mm | 2 minutes ago ...44 minutes ago |
45 至 89 分钟 | h | an hour ago |
90 分钟到 21 小时 | hh | 2 hours ago ...21 hours ago |
22 至 35 小时 | d | a day ago |
36 小时至 25 天 | dd | 2 days ago ...25 days ago |
26 至 45 天 | M | a month ago |
46 days to 10 months | MM | 2 months ago ...10 months ago |
11 months to 17months | y | a year ago |
18 months+ | yy | 2 years ago ...20 years ago |