Neighbourhood Party Manager
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

react-timestamp

4.4.0 • Public • Published

Timestamp

A React component for displaying a datetime in the local timezone

Usage

npm install react-timestamp

Then:

const Timestamp = require('react-timestamp');

Use UTC times for the time prop.

<Timestamp time={thing.created_at} />
<Timestamp time={thing.created_at} twentyFourHour />
<Timestamp time={thing.created_at} actualSeconds /> <!-- Shows actual seconds instead of 'a few seconds ago' -->
<Timestamp time={thing.created_at} precision={2} />
<Timestamp time="2015-10-10 10:30:00" format='full' />
<Timestamp time="2015-10-10 10:30:00" utc={false} format='full' /> <!-- Don't convert the timestamp to local time -->
<Timestamp time="1450663457" />
<Timestamp time="1450663457" format='full' includeDay />
<Timestamp time="1450663457" since="145060000" />
<Timestamp time="1450663457" until="145070000" />
<Timestamp time="1450663457" until="145070000" autoUpdate /> <!-- Updates every second -->
<Timestamp time="1450663457" until="145070000" autoUpdate={60} /> <!-- Updates every minute -->

Format options are:

  • 'ago' (default) - 2 hours ago
  • 'full' - 10 Oct 2015, 4:32pm
  • 'date' - 10 Oct 2015
  • 'time' - 4:32pm

Precision works like this:

<Timestamp time={SOME DATEprecision={3} />
<!-- 2 days, 4 hours, 1 minute ago -->
 
<Timestamp time={SOME DATEprecision={2} />
<!-- 2 days, 4 hours -->
 
<Timestamp time={SOME DATEprecision={1} />
<!-- 2 days -->

Usage with React Native

If you are using React Native then you'll have to pass in Text.

import Timestamp from 'react-timestamp';
import { Text } from 'react-native';

Then:

<Timestamp time="1450663457" component={Text} />

Testing

npm test

install

npm i react-timestamp

Downloadsweekly downloads

1,108

version

4.4.0

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability