[开源] timeago-react 简单高效的实时组件 '3 hours ago'
发布于 8 年前 作者 hustcc 3356 次浏览 来自 分享

timeago-react

一个非常简单的 react 组件,用于见时间格式化成 *** time ago 格式。 eg: ‘3 hours ago’。

实时渲染比较高效,很足 timeago 组件是每秒渲染一次,实际上对于时间是小时级别的,只需要每小时变化一次即可,同理,对于 3 years ago 的时间,是需要每年变化一次即可。

The component based on timeago.js.本身只有2kb大小,所以这个组件是非常轻量级的,不会动辄占用几十kb,甚至依赖jquery。

github 地址:https://github.com/hustcc/timeago-react

Build Status npm npm npm

1. 安装

npm install timeago-react

2. 使用

非常简单。

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)

将要被格式化的时间,可以是时间格式的字符串,时间对象,也可以是时间戳。

  • live (optional, boolean)

是否实时渲染,默认为 true 。

  • className (optional, string)

组件的 class 属性,可以用来设置 css 样式。

  • local (optional, string)

语言, 默认是 en. zh_CN and en 是支持的。

1 回复

mark<br><br>来自疯狂的<a href=“https://github.com/1340641314/react-cnode” target="_blank">react-cnode</a>

回到顶部