🕗 Simple and efficient react component to format date with `*** time ago` statement. eg: '3 hours ago'.
JavaScript HTML
Switch branches/tags
Nothing to show
Clone or download
xiaowei.wzw xiaowei.wzw
xiaowei.wzw and xiaowei.wzw fixed readme typo
Latest commit efa82d9 Aug 9, 2017



timeago-react is a simple react component used to format date with *** time ago statement. eg: '3 hours ago'.

The component based on timeago.js which is a simple javascript module.

  • Realtime render. Automatic release the resources.
  • Simple. Only 2kb.
  • Efficient. When the time is 3 hour ago, the interval will an hour (3600 * 1000 ms).
  • Locales supported.

Build Status npm npm npm react supported

1. install

npm install timeago-react

2. usage

import React from 'react';
import TimeAgo from 'timeago-react'; // var TimeAgo = require('timeago-react');

  datetime={'2016-08-08 08:08:08'} 
  locale='zh_CN' />

3. component props

  • datetime (required, string / Date / timestamp)

The datetime to be formated. can be datetime string, Date instance, or timestamp.

  • live (optional, boolean)

Live render, default is true.

  • className (optional, string)

The class of span. you can setting the css style of span by class name.

  • locale (optional, string)

The locale language of statement, default is en. All supported locales here. If you want to use locale which is not zh_CN / en, you should import the locale before use it. As below:

import React from 'react';
import TimeAgo from 'timeago-react';
import timeago from 'timeago.js';

// import it first.
timeago.register('vi', require('timeago.js/locales/vi'));

// then use it.
  datetime={'2016-08-08 08:08:08'} 
  locale='vi' />
  • style (optional, object)

The style object to applied to the root element.

Props not documented above are applied to the root element.