[开源] timeago-react 简单高效的实时组件 '3 hours ago'

timeago-react

一个很是简单的 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

Build Status npm npm npm

1. 安装

npm install timeago-react

2. 使用

很是简单。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' />

3. 组件属性

  • 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

相关文章
相关标签/搜索