All Projects β†’ simonlc β†’ Epoch Timeago

simonlc / Epoch Timeago

πŸ•“ Convert unix time to a relative time string e.g., "4 hours ago".

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Epoch Timeago

Mevn Cli
Light speed setup for MEVN(Mongo Express Vue Node) Apps
Stars: ✭ 696 (+3380%)
Mutual labels:  npm-package
Github Spray
Draw on your GitHub contribution graph β–‘β–’β–“β–ˆ
Stars: ✭ 908 (+4440%)
Mutual labels:  npm-package
Ostrio Analytics
πŸ“Š Visitor's analytics tracking code for ostr.io service
Stars: ✭ 9 (-55%)
Mutual labels:  npm-package
Bundlephobia
πŸ‹οΈ Find out the cost of adding a new frontend dependency to your project
Stars: ✭ 6,640 (+33100%)
Mutual labels:  npm-package
Terminal Image
Display images in the terminal
Stars: ✭ 778 (+3790%)
Mutual labels:  npm-package
React Timeline Carousel
React Timeline Feed Slider [UI Component]
Stars: ✭ 23 (+15%)
Mutual labels:  npm-package
Rando.js
The world's easiest, most powerful random function.
Stars: ✭ 659 (+3195%)
Mutual labels:  npm-package
Bmp085
A node.js module for reading a BMP085 barometer sensor.
Stars: ✭ 11 (-45%)
Mutual labels:  npm-package
Chat Codes
Encode and decode guildwars2 chat codes
Stars: ✭ 5 (-75%)
Mutual labels:  npm-package
Angular Loading Feedback
Angular directive to indicate loads in app
Stars: ✭ 8 (-60%)
Mutual labels:  npm-package
Np
A better `npm publish`
Stars: ✭ 6,401 (+31905%)
Mutual labels:  npm-package
Ky
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
Stars: ✭ 7,047 (+35135%)
Mutual labels:  npm-package
Fanyi
A πŸ‡¨πŸ‡³ and πŸ‡ΊπŸ‡Έ translate tool in your command line.
Stars: ✭ 940 (+4600%)
Mutual labels:  npm-package
Conf
Simple config handling for your app or module
Stars: ✭ 707 (+3435%)
Mutual labels:  npm-package
Sierra
Sierra SCSS library
Stars: ✭ 852 (+4160%)
Mutual labels:  npm-package
Node Module Boilerplate
Boilerplate to kickstart creating a Node.js module
Stars: ✭ 668 (+3240%)
Mutual labels:  npm-package
Easy Mock Server
A mock server for json and mock template files
Stars: ✭ 22 (+10%)
Mutual labels:  npm-package
Yarpm
CLI tool to run npm scripts with either npm or yarn, depending on how it was started
Stars: ✭ 13 (-35%)
Mutual labels:  npm-package
Electron Util
Useful utilities for Electron apps and modules
Stars: ✭ 854 (+4170%)
Mutual labels:  npm-package
Tb Cli
πŸ› οΈ CLI for rapid TB generate
Stars: ✭ 8 (-60%)
Mutual labels:  npm-package

Epoch TimeAgo

NPM npm bundle size (minified + gzip) npm downloads Deps Build Coverage

Convert Unix time to a relative time string e.g., "4 hours ago".

As the name implies, only epoch time (Unix time) can be used. The output format is similar to what you would find on Reddit.

There is zero configuration. Zero dependencies. Minifies to 435 bytes, and gzips to 224 bytes. 😎

Examples:

  • seconds > just now
  • minutes > a minute ago, 15 minutes ago
  • hours > an hour ago, 2 hours ago
  • days > 1 day ago, 2 days ago
  • weeks > 1 week ago, 3 weeks ago
  • months > 1 month ago, 5 months ago
  • years > 1 year ago, 2 years ago

Install

yarn add epoch-timeago

or

npm install -S epoch-timeago

The default build selected will depend on your bundle tool configuration. By default webpack will get the UMD build, and Rollup the esm build. If you want to override this use the following paths:

  • UMD build available at 'epoch-timeago/dist',
  • Commonjs build available at 'epoch-timeago/lib',
  • esm build (ES6+ only) available at 'epoch-timeago/es'.
  • Source (ES6+ only) available at 'epoch-timeago/src'.

NOTE: Builds are all minified.

Usage

Simply pass a Unix time stamp converted to milliseconds (timestampInSeconds * 1000) and get a time ago formatted string. If your timestamps are in milliseconds no conversion is necessary.

import timeago from 'epoch-timeago';

// Example of simple usage
const timeDiff = timeago(timestamp * 1000)

//Example of formatted string
const timeSince = timeago(Date.now() - 60000 * 10);
// '10 minutes ago'

In React

import React from 'react';
import timeago from 'epoch-timeago';

const TimeAgo = ({ time }) =>
  <time datetime={new Date(time).toISOString()}>{timeago(time)}</time>

// ...

const epochTimeStamp = Date.now() - 60000 * 22;
<TimeAgo time={epochTimeStamp} />

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].