https://github.com/aharshac/react-relative-time
React Component for rendering relative dates as <time> HTML5 elements.
https://github.com/aharshac/react-relative-time
date-time nodejs nodejs-modules react react-component
Last synced: about 1 year ago
JSON representation
React Component for rendering relative dates as <time> HTML5 elements.
- Host: GitHub
- URL: https://github.com/aharshac/react-relative-time
- Owner: aharshac
- License: mit
- Created: 2017-04-20T11:07:40.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-20T20:08:47.000Z (about 9 years ago)
- Last Synced: 2025-04-16T02:56:47.156Z (about 1 year ago)
- Topics: date-time, nodejs, nodejs-modules, react, react-component
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# React Relative Time
[](https://www.collaborizm.com/) [](https://travis-ci.org/aharshac/react-relative-time)
[](https://nodei.co/npm/react-relative-time/)
React Component for rendering relative dates as `
Does not depend on [**moment.js**](https://github.com/moment/moment)
## Acknowledgement
This module was inspired by a few awesome open source projects.
* [**moment.js**](https://github.com/moment/moment)
* [**react-time**](https://github.com/andreypopp/react-time)
* [**timeago**](http://timeago.yarp.com/)
## Installation
```
npm install react-relative-time
```
## Usage
```jsx
import React from 'react'
import RelativeTime from 'react-relative-time'
class MyComponent extends React.Component {
render() {
let now = new Date()
let wasDate = new Date("Thu Jul 18 2013 15:48:59 GMT+0400")
return (
)
}
}
```
## Reference
### Attribute `value`
The input date and time, which will be displayed in relative terms to the present date and time.
Supported types:
* *Date* object
`new Date(2017, 3, 19, 22, 33, 44, 666)`
* *number* - UNIX timestamp in milliseconds
`1492630940000`
* *string* - ISO-8601 date string
`1970-01-01T00:00:00Z`
### Attribute `titleFormat`
The specifier for the date and time format to be shown in the `title` attribute.
Default: `iso8601`.
Supported formats:
* `iso8601` - ISO-8601 date string
* *Custom string placeholders*.
Replaces with numbered date/time. Text like "Sunday", "Mon", etc. are not supported.
Ex: `YYYY/MM/DD HH:mm`
Supported number placeholders:
```
M = month
D = date
H = hour
m = minute
s = second
```