一个很是简单的 react 组件,用于见时间格式化成 *** time ago
格式。 eg: '3 hours ago'。css
实时渲染比较高效,很足 timeago 组件是每秒渲染一次,实际上对于时间是小时级别的,只须要每小时变化一次便可,同理,对于 3 years ago 的时间,是须要每一年变化一次便可。react
The component based on timeago.js.,自己只有2kb大小,因此这个组件是很是轻量级的,不会动辄占用几十kb,甚至依赖jquery。jquery
github 地址:https://github.com/hustcc/timeago-reactgit
npm install timeago-react
很是简单。github
import React from 'react'; import TimeAgo from 'timeago-react'; // var TimeAgo = require('timeago-react'); <TimeAgo date={'2016-08-08 08:08:08'} local='zh_CN' />
date
(required, string / Date / timestamp)将要被格式化的时间,能够是时间格式的字符串,时间对象,也能够是时间戳。npm
live
(optional, boolean)是否实时渲染,默认为 true 。ui
className
(optional, string)组件的 class 属性,能够用来设置 css 样式。code
local
(optional, string)语言, 默认是 en
. zh_CN
and en
是支持的。component