[React Intl] Format a Date Relative to the Current Date Using react-intl FormattedRelative

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[React Intl] Format a Date Relative to the Current Date Using react-intl FormattedRelative相关的知识,希望对你有一定的参考价值。

Given a date, we’ll use the react-intl FormattedRelative component to render a date in a human readable format, such as “2 days ago”, in various languages.

We\'ll also see how to set the frequency of this component\'s rendering to make our app update the text in real-time.

 

                <FormattedRelative 
                  value={new Date(review.date)}
                  style="numeric"
                  />

 

Since the FormattedRelative component udpate in real time, so you can also control the update interval:

                <FormattedRelative 
                  value={new Date(review.date)}
                  updateInterval={1000}
                  style="numeric"
                  />

Notice that it will cause extra unecessary component render.

 

以上是关于[React Intl] Format a Date Relative to the Current Date Using react-intl FormattedRelative的主要内容,如果未能解决你的问题,请参考以下文章

[React Intl] Format Numbers with Separators and Currency Symbols using react-intl FormattedNumber(代码

Intl.NumberFormat#format 最大整数值

[React Intl] Render Content with Placeholders using react-intl FormattedMessage

使用 react-intl 组件/字符串国际化

[React Intl] Install and Configure the Entry Point of react-intl

为 react/react-intl 动态导入语言 json 文件