如果想尝试像 Twitter 一样格式化推文的时间,则可以使用 @hijonathan 的 moment.twitter 插件。
这是显示人类可读的时间戳的长短版本的简单方法。
moment().subtract(5, 'hours').twitterLong();
// 5 hours
是的,它可以进行智能多元化。
moment().subtract(1, 'hour').twitterLong();
// 1 hour
还不够短吗?
moment().subtract(6, 'days').twitterShort();
// 6d
If you're trying to format times for tweets like the way Twitter does, you can use the moment.twitter plugin by @hijonathan.
It's a simple way to display both short and long versions of human-readable timestamps.
moment().subtract(5, 'hours').twitterLong();
// 5 hours
Yes, it does smart pluralization.
moment().subtract(1, 'hour').twitterLong();
// 1 hour
Not short enough for you?
moment().subtract(6, 'days').twitterShort();
// 6d