简体   繁体   English

react-intl转换相对时间(例如3分钟50秒)

[英]react-intl translate relative time (like 3 minutes and 50 seconds)

I use a react-intl for translating an application. 我使用react-intl来翻译应用程序。 I got a time in seconds which repesents how long did it take to complete a task and I want to show this time as a relative time. 我有一个以秒为单位的时间,该时间代表完成一项任务需要多长时间,我想将此时间显示为相对时间。 ("2 minutes" instead of pure 120 seconds) (“ 2分钟”,而不是纯粹的120秒)

But when I use 但是当我使用

<FormattedRelative value={0} initialNow={1248341} />

the react-intl returns "21 minutes ago" instead of "2 weeks" is there any way to get rid of that "ago" phrase and show only the translated phrase for given time value? react-intl返回“ 21分钟前”而不是“ 2周”,有什么方法可以摆脱该“ ago”短语,并仅显示给定时间值的翻译短语?

I had the same problem and didn't found a clean way to do it with react-intl. 我遇到了同样的问题,但没有找到一种使用react-intl的干净方法。 Instead you can try using humanize-duration package, which seems to be doing good job. 相反,您可以尝试使用人性化持续时间软件包,这似乎做得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM