码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-07-28 21:02:57      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:pat   eric   read   att   view   udp   div   end   make   

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

标签:pat   eric   read   att   view   udp   div   end   make   

原文地址:http://www.cnblogs.com/Answer1215/p/7252403.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!