[開源] 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

相關文章
相關標籤/搜索