Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🕗 Simple and efficient react component to format date with `*** time ago` statement. eg: '3 hours ago'.

License

NotificationsYou must be signed in to change notification settings

hustcc/timeago-react

Repository files navigation

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

The component based ontimeago.js which is a simple javascript module.

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

npmbuilddemonpmreact supportednpm

Install

npm install timeago-react

Usage

import*asReactfrom'react';importTimeAgofrom'timeago-react';// var TimeAgo = require('timeago-react');<TimeAgodatetime={'2016-08-08 08:08:08'}locale='zh_CN'/>

Component props

  • datetime (required, string / Date / timestamp)

The datetime to be formatted. can bedatetime string,Date instance, ortimestamp.

  • live (optional, boolean)

Live render, default istrue.

  • className (optional, string)

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

  • opts.relativeDate (optional, string / Date / timestamp)

The datetime to be calculated interval relative to.

  • opts.minInterval (optional, number in seconds)

The min interval in seconds to update the ** time ago string

  • locale (optional, string)

Thelocale language of statement, default isen. All supported localeshere. If you want to use locale which is notzh_CN /en, you should import the locale before use it. As below:

import*asReactfrom'react';importTimeAgofrom'timeago-react';import*astimeagofrom'timeago.js';// import it first.importvifrom'timeago.js/lib/lang/vi';// register it.timeago.register('vi',vi);// then use it.<TimeAgodatetime={'2016-08-08 08:08:08'}locale='vi'/>
  • style (optional, object)

Thestyle object to applied to the root element.

Props not documented above are applied to the root element.

LICENSE

MIT


[8]ページ先頭

©2009-2025 Movatter.jp